Part 1
In this puzzle we have to find the ideal time to start a ball through rotating discs. Each disc has multiple closed positions, one open position and rotate one position per second. We need to find the start time. so each disc is on the open position while the ball is falling through.
We can model this problem as finding a start time t, such that (initial_position + t + #disc) % #positions) = 0 for all discs 1 to n. This is the same as t % positions = (t + #disc) % positions for all discs. Problems in this form can be solved via the Chinese remainder theorem. I used an implementation from Rosetta code, so the programming work here was mostly parsing the input.
No comments:
Post a Comment