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`.

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:

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:

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:

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).

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).

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:

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.

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.

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.

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.

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.

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.

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:

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.

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

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.

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.

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.

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.

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).

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.

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.

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?

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:

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.

Eventually, another solution in Haskell!

Mathematica

My pilgrimage to spread Racket solutions to the agnostic masses nears the end

C#

C#

Java

Pen and paper (and a tiny bit Rust)

Julia

Solved using

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`.

Go! Golang!

In Kotlin

Python 3, Part1&2 in 4ms, 38 sloc

Rust (0.04s)

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:

956/1605

golfed m4

Here's an updated, although more verbose,

Julia

Rosette / Racket

Julia

JavaScript

Python

Go

C#

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:

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.

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:

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).

Python 3.8

Idris2 -

This was a tough one:

Please follow the

Elixir

Pen and paper

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).

Elixir

Kotlin

Solutions in C++

Go/Golang solutions

Kotlin. Brute force with memoization.

JavaScript

Rust

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:

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.

Nim

Rust

Pen and paper

Didn't get to use my ALU interpreter for the actual solution

Typescript

I ended up using the exact same strategy as you, in JS.

Lua

Python:

Python:

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.

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

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

ABAP

Rust

Clojure (

Perl / C

Please follow the

[ŅÐīÐ°ÐŧÐĩÐ―Ðū]

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.

R / Rlang

Python 3

AWK, C and Excel

Mathematica

Python 3

took me way to long to understand this

very nice, thanks for sharing!

This is a really neat solution!

C#

Python

This is in theory a Rust solution:

I solved this initially by translating the program to

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

Here's a black-box solution using the

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.

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.

Rust:

A not very optimal

Update

Scala solution

Go

Clojure Excel

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.

Dart

Python, general purpose:

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.

extremely elegant and readable for such a problem. well done that is impressive

wow, that is short!

You and I have different definitions of general purpose.

[ŅÐīÐ°ÐŧÐĩÐ―Ðū]

[ŅÐīÐ°ÐŧÐĩÐ―Ðū]

C

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!

language: julia

Python 3.10, general solver:

the writeup is excellent. really enjoyed going through it -- I aspire to write like this some day.

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

Python 3

JavaScript

Zig

After doing it

Edit: After solving by hand I also wrote the solution in rust, so that it works with any input.

Swift:

what made you decide to try the creatively bonkers idea of using genetic algorithms for this

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

Python 3.

O(1) solution in go

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:

Rust

ES6

scheme (racket)

C++

Please follow the

Python 3 Math

Golang

Generic math solution in

Hi, can you say who you get this for a in [0, A-1]? as the solutions for equations for z?

I believe that A is always 26 when B is negative, and 1 when B is positive.

Astounding. Sometimes I feel like I'm just banging rocks together here.

Fortran (with the help of python) [code as text:

Nice. I tried something similar but it would have taken about a day of CPU time to run through the entire space.

Rust

works on mine

golang

Brute force with memoization in

Javascript

JS | JAVASCRIPT | NODE

Please follow the

C#

C# 1515/1431

Typescript

TypeScript

My solution in Common Lisp

Python3

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.

RUST

C#

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

R / Rlang

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.

Did you reverse engineer the ALU logic based on the version of your input data?

R / Rlang

Nice explanation: I figured this out as well but I didn't fully understand why this was true.

Rust

R

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.

Python 3

Rust

Manual / GOlang

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.

Egel

C++

Python 30/23

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.

R / baseR / Rlang

Python:

Worked for part1 but for part 2 it says the solution ist too high :/

Haskell

my rust solution

PHP

Python 3.

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).

Like so many others, I worked out my answer on "

Python 3 (no imports, both parts)

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.

THANK YOU, this really helped me when I was stuck!

Python

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.

Rockstar

wtf?

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.

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?

Rust, Brute Force, < 1min

I like the approach of branching the state at each input. How long does it take to process all the states?

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:

Post removed due to naughty language. Keep

Rust part 2

SICStus Prolog

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.

1795/1707 Python, 18 lines, should work for any input

It sure won't work for any valid input. It will likely work for all inputs given by the site though ;)

As with everyone way, wayyyy to much analysis.... it's 6am now... heh

Nice, it seems that we have independently arrived at an

Wow,

python

Congratulations, you've came up with and implemented Concolic Execution a la

Python "Precompiled solution" featured on

Ruby

Python, both parts

I solved it by hand with some assistance from Python. First I converted the input to this program: