-🎄- 2021 Day 24 Solutions -🎄-

  1. This is really interesting, but I'm running into an issue with both your program and my version where I get MiniZinc: type error: no function or predicate with name_toString_Immediates' found`.

  2. Triple backticks do not work on old.reddit. Please edit your post to use the four-spaces code block Markdown as per our posting guidelines in the wiki:

  3. About a hundred iterations of this ago I started out parsing the input into a linq Expression tree that could be compiled and run. This was all very promising til it ended up in the bin after I realised I didn't actually need to "run" the program. Snippet for interest:

  4. Ended up writing a full optimizing compiler in Rust, where solving day24 is just one part of the functionality. It solves the problem in 0.2s.

  5. Your code is hard to read on old.reddit when everything is inlined like this and gets cut off at the edge of the window. Please edit it to use a proper code block as per our posting guidelines in the wiki:

  6. I started with a brute force... While waiting for it to finish (fo-re-ver), I tried to simplify instructions to make the brute force approach quicker. While doing that, I started to see the patterns... I couldn't put my finger on it, so decided to check this thread for clues. In the end, I got a relatively simple solution that does exactly what my naked eye could also do (together with pen and paper).

  7. Oh, that's interesting. I believe my solution is very similar, but based on "let's see if this works or if I need to do more to find the max input" instead of sound reasoning, so it was a nice surprise when my first attempted answer was actually correct for both parts. :-) After looking at the ALU instructions for some time, I wrote the logic down in pseudo code, which finally helped (I implemented useless things like an ALU instruction optimizer and a "bounded integer execution" earlier, then I gave up temporarily).

  8. My first time commenting but just came here to say how much I enjoyed this puzzle. I went down loads of the rabbitholes here gradually getting more and more complex in my analysis of the code but as I started optimizing at every step (being aware that the "mod 26" at any step would always correspond to a specific digit because the offset was never greater than 15 = 26-9) it eventually became apparent that the digits are effectively paired with each other and the algorithm could be reduced to just:

  9. I also enjoyed this one a lot, but I can understand some people did not like having to “solve for the input”. Once you notice the pairing, though, it becomes so simple. I kind of brute forced the search for section pairs by trying all input values with all subsequent pairs. The ones that left z at zero I removed and repeated until there were no sections left.

  10. I very much like your elegant solution, but it doesn't seem to be able to solve the problem for every input. This appears to be because it doesn't take every possible z into account when going backward through the iterations.

  11. Thanks for sharing, your backwards function saved me some headaches. This was the most 'out of my league' problem for me.

  12. this is the most clever and concise solution i've seen so far. thank you very much for sharing!

  13. The code could do with some refactoring to eliminate the many copy/paste/edit blocks, but while I was writing it, the previous version of the code was still running and still generating useful output.

  14. I'm impressed - your awk solution fits in 186 bytes and outputs both parts at once. Originally, I could only get my golfed

  15. I wonder whether Z3 would actually be effective here. Generally speaking, boolector/bitwuzla are considerably stronger than Z3 on quantifier-free bit-vector problems like this one.

  16. I recommend you include Python in your post as well. This makes it easier for folks who Ctrl-F the megathreads looking for a specific language.

  17. The stockings are hung, everything is ready for tomorrow morning, and my brain couldn't stop thinking, so I finished the 'reverse-engineer' version which just examines the digit-specific parameters, matches up the mult/divide column pairs, and finds the valid ranges of digits for each column.

  18. This is awesome and also easily translatable. Was able to integrate this into my program. Otherwise I probably would never have gotten a solution at all.

  19. Awesome solution! I come to the same conclusion about z, but couldn't figure out how to implement it. I really liked your recursive search!

  20. Super great solution and write up. I never thought of it as a stack but it does make sense, though through the haze of staring at my

  21. For the love of god. I was traveling yesterday and failed to find the time for amorphopods. Which are still causing a headache.

  22. Triple backticks do not work on old.reddit. Please edit your post to use the four-spaces code block Markdown as per our posting guidelines in the wiki:

  23. I actually did something quite similar - I began by realizing that if z1 == 0 for the final digit, I could calculate all valid candidate inputs for w and z0. Then z0 must be the z1 of the prior digit's instruction block, and I could repeat the process.

  24. Today nearly killed me. I have done every day up to today without getting any help or looking at anybody else's solutions, but I spent hours today de-compiling the code and was very close but not quite there. With the help of

  25. I tried long and hard to solve todays puzzle but it wasnt working. Tried doing it by hand but I kept making small mistakes and then started questioning if its even worth continuing because Im sure I made even more mistakes I didnt notice.

  26. By hand. As have others, I noted the pattern where either you always grow by z->26z+num or z->z//26 if num is negative, assuming you pass a mod check where w=z+num2 mod 26. There are 7 increases, so you had better pass that mod check each time to get back to zero. Let's say we're in a check state and we grew last time. then z_i=26z_{i-1}+num2_{i-1}, so w_i=num_{i-1}+num2_i. The second key is that every time you shrink, you forget one cycle of growth, so if num_{i+1} is also negative, you need to check against z_{i-2} (assuming that was a growth). Because every grow/shrink pair leaves z unchanged, if you're a repeated negative, you had better skip each matched grow/shrink pair to find the one you correspond to. In my case, the negative nums were at indices [4,6,9,10,11,12,13], so 4 checks against 3, 6 checks against 5, 9 checks against 8, 10 against 7, 11 against 2 (since 3/4 and 5/6 undid each other), 12 against 1 and 13 against 0. That gives a set of 7 statements like w13=w0+num_0+num2_13. As a sanity check, w13 had better end up getting compared to w0 or you have a bug.

  27. I actually put my paper solving method into code which computes both solutions in 110 μs on my MB Pro in case somebody wants to check their solutions. I indicated which lines to uncomment to get the analysis output that led to the paper solution.

  28. I had to increase the cap to get your solution to work for my input (265 instead of 264). With a lower cap, it provides no solution for part 1. Great solution, otherwise, though.

  29. I really like your way of doing this. I didn't believe it would actually work but confirmed it works even with my input (so now I'm wondering if all inputs have adds on lines 6 and 16).

  30. Ruby, 2504/2383. I took a 5-hour break after the leaderboard capped. Converting assembly code into Excel helps me to understand the code more easily.

  31. Did pretty much this as well, although a bit simpler: still used input parser for executing each step/digit, and just cut out any z-states that were high enough. (> 1e6) . Runs in about 10 secs.

  32. Kotlin, both parts combined solved in ~50ms "on the first try" (no bruteforcing) on any input. Pretty proud of it, altough it took me 6 hours to get to this point.

  33. I would love to understand how you translated the instructions in the program into this logic. How did you understand that it was a push/pop system referencing indices for the resulting "good" digit? What about the code led you to that?

  34. I didn't build a generic solution, but converted the code to Kotlin and refactored it into something more readable. Since I saw % 26 and / 26 all over the place, I decided to store intermediate results as letters. I identified two subroutines:

  35. Interesting. I labeled only the input after recursing through creating the constraints between the input and the desired result. I admit I was excited to finally get to use clfpd for something where it was actually appropriate.

Leave a Reply

Your email address will not be published. Required fields are marked *