r/adventofcode • u/Sostratus • Dec 24 '21
Help [2021 Day #24] How do you approach this programmatically?
I've solved day 24 now, but in the end I didn't write a single line of code. I just scribbled notes on a spreadsheet for hours as I broke down what the MONAD does. And now even with hindsight, I have no idea what the efficient way to tackle it would have been.
As I read the problem description I was at first thinking about how to parse and simulate these ALU instructions, but once I finished reading it didn't seem like that would help at all. The only apparent programming solution to me was to try every possible model number which isn't feasible.
So how do you write code to help you read code? I could write a program to pull the key constants from the input and calculate the max and min model numbers, but once you even know to do that the problem is 99% done.
View all comments
Show parent comment
4
u/Mahrgell2 Dec 24 '21
Wow, I never looked at the memory consumption of my solution. Thanks for pointing this out.
It really takes up 12GB peak memory usage. :D (when computing task1 and 2 simultanously, thats 2 instead of 1 u64 tracked per state).
I think the main memory peaks are from the HashMap I use to collapse solutions when branching out the inp instructions.
This could be reduced by first reducing before branching. Alternatively not tripling all states (the states before the input instruction, the temporary hashmap and my states after the input) would also dramatically reduce memory consumption, but that way I had it was way easier to keep it fast.
But I guess a few more thoughts and lines into that and this can be kept at around 4GB.
But well, I never claimed my solution to be optimized. Its just brute force :D