From d30c28527b8e32db0a0702cb2661783176db03e3 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Fri, 13 Dec 2019 09:51:59 -0500 Subject: [PATCH] Fix bug in day 12 that wouldn't check velocities --- day12/py/main.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/day12/py/main.py b/day12/py/main.py index 5a2aeda..8e663c4 100644 --- a/day12/py/main.py +++ b/day12/py/main.py @@ -85,12 +85,12 @@ def part1(moons: Moon) -> int: def part2(moons: Moon) -> int: - # Count until we hit the same thing (1 indicates that it will take one simulation to get the same value again), - # i.e. a nop + VELOCITY_FIELD_SUFFIX = '_velocity' + # Count until we hit the a 0 velocity and identical position to the starting position counts = { - 'x': 1, - 'y': 1, - 'z': 1, + 'x': 0, + 'y': 0, + 'z': 0, } found_cycle = { @@ -107,7 +107,9 @@ def part2(moons: Moon) -> int: continue counts[key] += 1 - found_cycle[key] = all(getattr(original_moons[i], key) == getattr(moon, key) for i, moon in enumerate(moons)) + found_cycle[key] = all(getattr(original_moons[i], key) == getattr(moon, key) + and getattr(moons[i], key + VELOCITY_FIELD_SUFFIX) == 0 + for i, moon in enumerate(moons)) return functools.reduce(lcm, counts.values())