swlabr

joined 2 years ago
[–] [email protected] 2 points 1 month ago (2 children)

re: branch cuttingIDK if this is what your issue was, but one thing I ran into was that if you do something like if (current_total >= target) prune(), this can be problematic because if the tail end of the data is 0s and 1s, you exit too early. Basically I would prune strictly when the current total > target.

[–] [email protected] 2 points 1 month ago* (last edited 1 month ago) (6 children)

Day 7

1 and 2On reflection, it was a pretty fun little problem to solve. There wasn't much of a difference between the two parts. I ran into some bugs with my recursion termination conditions, but I got them in the end.

Part 1. A quick look at the data showed that the input length was short enough to perform an O(2^n^) search with some early exits. I coded it as a dfs.

Part 2. Adding concatenation just changes the base from 2 to 3, which, while strictly slower, wasn't much slower for this input.

code

void d7(bool sub) => print(getLines()
    .map((l) => l.split(RegExp(r':? ')).map(int.parse).toList())
    .fold<int>(
        0, (p, ops) => test(ops, ops[0], ops[1], 2, sub) ? ops[0] + p : p));

bool test(List<int> l, int cal, int cur, int i, bool sub) =>
    cur == cal && i == l.length ||
    (i < l.length && cur <= cal) &&
        (test(l, cal, cur + l[i], i + 1, sub) ||
            test(l, cal, cur * l[i], i + 1, sub) ||
            (sub && test(l, cal, cur.concat(l[i]), i + 1, sub)));

[–] [email protected] 8 points 1 month ago (1 children)

Just forwarding along the last mention of this by @blakestacey

Stubsack

Which links to this discourse

[–] [email protected] 6 points 1 month ago

Fucking hell. What exactly do they pay Salty Ballman for if all he does is come up the same ideas over and over? Just replace him with a coin with “cram another LLM into the trenchcoat” on one side and “add another payment tier” on the other.

Worst fake techonology revolution ever. This bubble can’t burst fast enough.

[–] [email protected] 9 points 1 month ago (1 children)

I have heard that egg nog and orange soda is a surprisingly good drink.

[–] [email protected] 10 points 1 month ago (1 children)

Sundar Pichai says Google Search will ‘enshittify profoundly’ in 2025 [paraphrasing]

[–] [email protected] 15 points 1 month ago

as the edgy commie teens say, praxis

[–] [email protected] 1 points 1 month ago* (last edited 1 month ago)

code for day 5, written in dart to be short:

spoiler

void d5(bool isPart2) {
  Map<int, Set<int>> ordering = {};
  int comp(int a, int b) => ordering[a]?.contains(b) ?? false ? -1 : 1;

  List<String> lines = getLines();
  int rulesEnd = lines.indexWhere((line) => line.isEmpty);

  lines
      .sublist(0, rulesEnd)
      .map((line) => line.split('|').map((e) => int.parse(e)).toList())
      .forEach((rule) => ordering.putIfAbsent(rule[0], Set.new).add(rule[1]));

  print(lines
      .sublist(rulesEnd + 1)
      .map((line) => line.split(",").map((s) => int.parse(s)).toList())
      .fold<int>(
          0,
          (p, e) =>
              p +
              (e.isSorted(comp) != isPart2
                  ? e.sorted(comp)[e.length >> 1]
                  : 0)));
}

[–] [email protected] 1 points 1 month ago (2 children)

days 5 and 6.

5:

p1, p2:Initially, I was thrown for a loop. It wasn't apparent to me what data structure to use or the problem's properties. My first (and correct) instinct was to interpret the data as a directed graph, but then what? Try to find some total ordering, if such a thing was possible?

As it turns out, that instinct was also correct. By drawing the sample data (or counting or printing it out), I noticed that every page number had a defined relation with every other page number. This meant that a total ordering (rather than a lattice) existed, meaning it was possible to construct a comparison function.

So, the algorithm for part 1 was to check if a list was sorted, and part 2 was to sort the list. There's probably a 1-3 line solution for both parts a and b, but that's for Mr. The Reader.

6:

p1, p2as discussed in a different part of the thread, I consider the input size for square inputs to be N, the "side length" of the square.

Context: I participated (and completed!) in AoC last year and pragmatically wrote my code as a set of utility modules for solving these pathological problems. So, I had about 80% of the boilerplate for this problem written, waiting for me to read and relearn.

Anyway, the analysis: P1. was pretty straightforward. Just walk along the map, turn right if you hit an obstacle, and stop when you leave the map. I guessed that there may be a case where one needs to turn in place more than once to escape an obstacle, but I never checked if that was true. Either way, I got the answer out. This is a worst-case O(n^2^) solution, which was fast for n = 130.

P2. I chose to brute force this, and it was fine. I iterated through the grid, placing a wall if possible, and checked if this produced a loop using an explored set. This is worst case O(n^4^), which, for n=130, takes a few seconds to spit out the answer. It's parallelisable, though, so there's that. If a faster solution existed, I'd love to know.

[–] [email protected] 2 points 1 month ago

i am a simple manI see square input, i say n^2^

[–] [email protected] 11 points 1 month ago (1 children)

it's almost as if international trade of weapons creates perverse incentives

[–] [email protected] 6 points 1 month ago* (last edited 1 month ago) (1 children)

Or a secret, third option:

view more: ‹ prev next ›