Summary for those just joining us:
Advent of Code is an annual Christmas themed coding challenge that runs from December 1st until christmas. Each day the coding problems get progressively harder. We have a leaderboard and pretty good turnout, so feel free to hop in at any time and show your stuff!
Whether you have a single line monstrosity or a beautiful phone book sized stack of OOP code, you can export it in a nice little image for sharing at https://carbon.vercel.app
What did you think about today's problem?
Our Code is 2416137-393b284c (No need to share your profile, you have the option to join anonymously if you don't want us to see your github)
Jump in the discussion.
No email address required.
Hmm. This was easy to code but there's gotta be a better way. Takes forever to execute. Although after n iterations the answer is consistent so I didn't even run at a million.
I don't get it tho how does this get optimized..? Even if I turn it into 2 things by flipping the table and just doing 1 direction four times, it'd still be the same amount of work wouldn't it..?
Jump in the discussion.
No email address required.
You got lucky.
The main optimization (if it could even be called that) is to find a cycle by storing all states
you get after four tilts (or their hashes), then reduce
that billion iterations modulo the cycle length. That gave me about two minutes' run time in Python
on my data.
The next part I guess
is to make the tilt step dramatically faster by placing the rocks into their final
places immediately instead of running
the cellular automata on the entire grid all the time.
Jump in the discussion.
No email address required.
For my tilt I just counted the number of 0s between each hash and just placed that many. No need to iterate each of them into place since they're all identical. It runs in order of milliseconds at that point
Jump in the discussion.
No email address required.
More options
Context
ah yea ur right I have it assigning the value for each step, would be better to get the final number then do the swap
Jump in the discussion.
No email address required.
More options
Context
More options
Context
You answered your own question.
(1000000000 % cycle length) + offset is how many cycles you need to get the answer.
So for part two all you do is add a 90degree matrix rotation and tilt the table. Then just run until you see the pattern and adjust your required cycles
Jump in the discussion.
No email address required.
I didn't wanna assume cuz what if it's like
where there's a span of seemingly repetitive answers
But I "proved" it by submitted my answer for 100,1000,10000 lawl
Jump in the discussion.
No email address required.
If they managed to design a problem where the data did that it would be REALLY funny
Jump in the discussion.
No email address required.
it took 100000 iterations 80 seconds to run so.. yea pressing ctrl+c in the middle of the full run felt good after the answer got confirmed lolol
Jump in the discussion.
No email address required.
By the way it's not possible to have a loop that would break in this problem.
If the same position is EVER reached again it would work unless some outside stimulus was applied.
Jump in the discussion.
No email address required.
how hard do u think it would be, given the same placement of
#
rocks and same number ofO
rocks, to find what configuration would result in the highest number of iterations required where no more change is possiblee:
I don't think that's tru tho because the answer is itself a hash of the configuration isn't it? There's for sure collisions possible with one
O
switching places vertical places with anotherO
Jump in the discussion.
No email address required.
If they switch places it doesn't matter functionally. It still counts as a cycle for the purposes of this exercise as the only thing that matters is any rock being in that position.
From a black box perspective that cycle will continue forever in terms of output stress even if rocks are swapping positions because those swaps themselves will also be cyclical e.g. if two rocks switch, in another cycle they'll switch back, if three rocks rotate positions they'll be be back to their original position after two cycles and the same slots will still have been filled in the intermediary ones.
Don't consider them swapping a collision unless the two rocks are actually distinct in some way. Otherwise that's like calling binary number 0b101 a collision with 0b101 (with the numbers swapped)
Jump in the discussion.
No email address required.
More options
Context
More options
Context
More options
Context
More options
Context
More options
Context
More options
Context
More options
Context
More options
Context