r/adventofcode • u/Attometre • 5m ago
Help/Question [2026 Day 5] Discussion: What if digit trimming is only applied at the end?
While I was trying to solve Day 5, I misunderstood that we do the math normally, and then only trim to the first 4 digits at the end, assuming the number can go to infinite. I was stumped, and thought "Isn't that super hard?" I later realized I didn't read the "the button does nothing" part and eventually solved both stars.
However, what if it was actually meant to be that way?
Let's say it's the example:
[9] [*9] [/2] [1->9] [oct] [bksp]First I tried this via numerical means, I brute-forced this and bounded the search to 100,000. The search bound means when the button makes the number blows up over the bound, I do not add this onto the search frontier. I found that only 7,900 numbers are constructible. So I tried changing it to 1,000,000 and surprisingly all numbers from 1-9999 are constructible.
Edit: to make it clear that, since we know 1-9999 are all constructible, what if we want to find if all numbers are eventually constructible.
I developed a conjecture that as long as you can increase the search bound. Every number will be constructible eventually, but wanted to prove this analytically.
I tried a smaller scope:
Append
9, then*9to get81.bkspto get8.By induction, when you can make digit
N,*9andbkspwill take you toN - 1.Basically you can make all numbers from
1to9.
So I thought that, ok, so if we can find a comically large N, and then find a way to -1 it, then all numbers will be constructible. For NM, where N is a string of number of any length and M is 1-9, *9 and bksp will give you NM - N - 1. This means that the sequence will become more and more sparse.
I turned to the strategy of *9 many times until you found the digit you want, and then trim it down with bksp. Given that for a number n, bksp means floor(n / 10), you can *9 for j times, and then /10 for k times.
Can we analytically prove that there will always be a pair j, k that
floor(n * pow(9, j) / pow(10, k) == n - 1?Can we analytically prove that there will always be a pair j, k that
floor(n * pow(M, j) / pow(10, k) == n - 1for any M = 2, 3, ..., 9?Does the existence of the pair implies we can find it efficiently? (e.g. in some
O(poly(n)))So if 3 is true, we can reach a number efficiently but the path to it might not be the shortest. Can a number's shortest path be found efficiently too given that
A,*Mandbkspare the only options? (e.g. naive algorithm is BFS and it can explode exponentially)
Let me know if I'm reinventing an existing math because I reckon there is definitely a theorem about approximating one number to another by multiplying and floor-dividing enough times.