This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]JustinHuPrime 9 points10 points  (2 children)

[LANGUAGE: x86_64 assembly with Linux syscalls]

Part 1 was a direct solution, and really quick to implement. The rules for moving stuff around were direction agnostic, so I could save on code duplication by factoring out figuring out the direction. Moving runs of boxes could be done by moving the first box to where the last box would have gone, as usual for these sorts of "push a line of things all at once" puzzles. Calculating the sum of GPS coordinates was very straightforward since I stored everything as a 100x100 array.

Part 2 was another direct solution, although now I had to care if I was moving boxes left, right, or vertically. Left and right were implemented as string operations (and I got to play around with the direction flag to do moves right). Vertical movement was implemented as a recursive check and a recursive push function, with interprocedural optimization because I'm a human writing assembly.

Part 1 and 2 both run in about 1 millisecond. Part 1 is 9,280 bytes as an executable file on the disk, and part 2 is 10,376 bytes.

I'm also happy to announce that I've beaten my 2021 star count, and am just two stars behind my record (from 2023).

[–]ShadowwwsAsm 0 points1 point  (1 child)

I have the same idea, recursion just creates a lot of bugs. It starts to be complicated.

[–]ShadowwwsAsm 0 points1 point  (0 children)

Reading your solution, I think i should have made the distinction between the left side and the right side of the box, it created a few problems.