|
|
|
|
@ -1,6 +1,9 @@ |
|
|
|
|
from itertools import permutations |
|
|
|
|
import os |
|
|
|
|
import re |
|
|
|
|
from copy import deepcopy |
|
|
|
|
from functools import reduce |
|
|
|
|
from itertools import permutations |
|
|
|
|
from math import gcd |
|
|
|
|
|
|
|
|
|
inputfile = os.path.join(os.path.dirname(__file__), "input/day12_input") |
|
|
|
|
|
|
|
|
|
@ -32,3 +35,28 @@ def test_day12a(): |
|
|
|
|
e += (abs(p[0])+abs(p[1])+abs(p[2]))*(abs(v[0])+abs(v[1])+abs(v[2])) |
|
|
|
|
|
|
|
|
|
assert e == 9139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_day12b(): |
|
|
|
|
""" |
|
|
|
|
Finished with helpful hints from ZuBsPaCe |
|
|
|
|
https://www.reddit.com/r/adventofcode/comments/e9jxh2/help_2019_day_12_part_2_what_am_i_not_seeing/far9cgu/ |
|
|
|
|
""" |
|
|
|
|
moons = [[m, [0, 0, 0]] for m in get_moons()] |
|
|
|
|
com = [] |
|
|
|
|
for i in range(3): |
|
|
|
|
count = 0 |
|
|
|
|
initial = deepcopy(moons) |
|
|
|
|
while True: |
|
|
|
|
for me, other in permutations(moons, 2): |
|
|
|
|
pa = me[0] |
|
|
|
|
pb = other[0] |
|
|
|
|
me[1][i] += -1 if pa[i] > pb[i] else 1 if pa[i] < pb[i] else 0 |
|
|
|
|
for moon in moons: |
|
|
|
|
moon[0][i] += moon[1][i] |
|
|
|
|
count += 1 |
|
|
|
|
if moons == initial: |
|
|
|
|
break |
|
|
|
|
com.append(count) |
|
|
|
|
steps = reduce(lambda a, b: int(a * b / gcd(a, b)), com) |
|
|
|
|
assert steps == 420788524631496 |
|
|
|
|
|