|
@@ -72,14 +72,18 @@ func energy(channel chan []int64, moons int) int64 {
|
72
|
72
|
|
73
|
73
|
// Sweeping assumptions/notes on how this mess works:
|
74
|
74
|
//
|
75
|
|
-// 1) the movement of the planets will be parabolic - they'll accelerate towards each other,
|
|
75
|
+// 1) the movement of the moons will be parabolic - they'll accelerate towards each other,
|
76
|
76
|
// then gradually slow down to a complete stop and reverse path going back to the starting point.
|
77
|
77
|
// I'm not sure I can prove that's the case in general, but it does seem to hold true.
|
78
|
78
|
//
|
79
|
|
-// 2) the middle of the parabola occurs after step 1000 (otherwise the code would need a fiddly bit of
|
|
79
|
+// 2) all the moons will hit the inflection point of the parabola at the same step. I think this is reasonable
|
|
80
|
+// as each force is mirrored, so bodies accelerating towards one another will end up with the same total velocity
|
|
81
|
+// when they cross
|
|
82
|
+//
|
|
83
|
+// 3) the middle of the parabola occurs after step 1000 (otherwise the code would need a fiddly bit of
|
80
|
84
|
// state tracking to ensure it returned a value for part 1).
|
81
|
85
|
//
|
82
|
|
-// 3) because the axes are independent, they can be simulated in parallel, and their individual parabolic inflection
|
|
86
|
+// 4) because the axes are independent, they can be simulated in parallel, and their individual parabolic inflection
|
83
|
87
|
// points found. This gives us the loop count for each axis (2x the number of steps to reach the inflection point),
|
84
|
88
|
// and we can find the first time all three axis's loops intersect by finding the lowest common multiple of those
|
85
|
89
|
// three values.
|
|
@@ -88,7 +92,7 @@ func energy(channel chan []int64, moons int) int64 {
|
88
|
92
|
//
|
89
|
93
|
// <------------------- position on axis ------------------>
|
90
|
94
|
//
|
91
|
|
-// __,..--'"" |
|
|
95
|
+// (somewhere) __,..--'"" |
|
92
|
96
|
// step 1000 _,..--'"" ^ |
|
93
|
97
|
// v _,..-'"" start |
|
94
|
98
|
// _,..-'" vel = 0 |
|