aoc-2019-c

Advent of Code 2019 Solutions in C
git clone https://git.sinitax.com/sinitax/aoc-2019-c
Log | Files | Refs | README | sfeed.txt

part2 (1945B)


      1--- Part Two ---
      2
      3All this drifting around in space makes you wonder about the nature of the universe.  Does history
      4really repeat itself?  You're curious whether the moons will ever return to a previous state.
      5
      6Determine the number of steps that must occur before all of the moons' positions and velocities
      7exactly match a previous point in time.
      8
      9For example, the first example above takes 2772 steps before they exactly match a previous point in
     10time; it eventually returns to the initial state:
     11
     12After 0 steps:
     13pos=<x= -1, y=  0, z=  2>, vel=<x=  0, y=  0, z=  0>
     14pos=<x=  2, y=-10, z= -7>, vel=<x=  0, y=  0, z=  0>
     15pos=<x=  4, y= -8, z=  8>, vel=<x=  0, y=  0, z=  0>
     16pos=<x=  3, y=  5, z= -1>, vel=<x=  0, y=  0, z=  0>
     17
     18After 2770 steps:
     19pos=<x=  2, y= -1, z=  1>, vel=<x= -3, y=  2, z=  2>
     20pos=<x=  3, y= -7, z= -4>, vel=<x=  2, y= -5, z= -6>
     21pos=<x=  1, y= -7, z=  5>, vel=<x=  0, y= -3, z=  6>
     22pos=<x=  2, y=  2, z=  0>, vel=<x=  1, y=  6, z= -2>
     23
     24After 2771 steps:
     25pos=<x= -1, y=  0, z=  2>, vel=<x= -3, y=  1, z=  1>
     26pos=<x=  2, y=-10, z= -7>, vel=<x= -1, y= -3, z= -3>
     27pos=<x=  4, y= -8, z=  8>, vel=<x=  3, y= -1, z=  3>
     28pos=<x=  3, y=  5, z= -1>, vel=<x=  1, y=  3, z= -1>
     29
     30After 2772 steps:
     31pos=<x= -1, y=  0, z=  2>, vel=<x=  0, y=  0, z=  0>
     32pos=<x=  2, y=-10, z= -7>, vel=<x=  0, y=  0, z=  0>
     33pos=<x=  4, y= -8, z=  8>, vel=<x=  0, y=  0, z=  0>
     34pos=<x=  3, y=  5, z= -1>, vel=<x=  0, y=  0, z=  0>
     35
     36Of course, the universe might last for a very long time before repeating.  Here's a copy of the
     37second example from above:
     38
     39<x=-8, y=-10, z=0>
     40<x=5, y=5, z=10>
     41<x=2, y=-7, z=3>
     42<x=9, y=-8, z=-3>
     43
     44This set of initial positions takes 4686774924 steps before it repeats a previous state! Clearly,
     45you might need to find a more efficient way to simulate the universe.
     46
     47How many steps does it take to reach the first state that exactly matches a previous state?
     48
     49