From 4d94f7424b8cc8ede20ef778458935e8118ec5f5 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Wed, 30 Nov 2022 07:42:23 +0100 Subject: [PATCH] day13 --- day13.py | 52 +++++++++++++++++++++++++++++++++++++++++++++ inputs/input13 | 44 ++++++++++++++++++++++++++++++++++++++ inputs/input13_test | 4 ++++ 3 files changed, 100 insertions(+) create mode 100644 day13.py create mode 100644 inputs/input13 create mode 100644 inputs/input13_test diff --git a/day13.py b/day13.py new file mode 100644 index 0000000..6e80fd2 --- /dev/null +++ b/day13.py @@ -0,0 +1,52 @@ +from tools.aoc import AOCDay +from typing import Any + + +def get_caught_mul(init: dict, delay: int = 0) -> int: + caught = 0 + for x, s in init.items(): + if (x + delay) % (s * 2) == 0: + if delay: + return 1 + else: + caught += x * (s + 1) + + return caught + + +class Day(AOCDay): + inputs = [ + [ + (24, "input13_test"), + (3184, "input13") + ], + [ + (10, "input13_test"), + (3878062, "input13") + ] + ] + + def get_input(self) -> dict: + ret = {} + state = {} + for line in self.getInput(): + l, d = map(int, line.split(": ")) + ret[l] = d - 1 + state[l] = [0, -1] + + return ret + + def part1(self) -> Any: + return get_caught_mul(self.get_input()) + + def part2(self) -> Any: + delay = 0 + init = self.get_input() + while get_caught_mul(init, delay): + delay += 1 + return delay + + +if __name__ == '__main__': + day = Day(2017, 13) + day.run(verbose=True) diff --git a/inputs/input13 b/inputs/input13 new file mode 100644 index 0000000..701ff7f --- /dev/null +++ b/inputs/input13 @@ -0,0 +1,44 @@ +0: 3 +1: 2 +2: 6 +4: 4 +6: 4 +8: 10 +10: 6 +12: 8 +14: 5 +16: 6 +18: 8 +20: 8 +22: 12 +24: 6 +26: 9 +28: 8 +30: 8 +32: 10 +34: 12 +36: 12 +38: 8 +40: 12 +42: 12 +44: 14 +46: 12 +48: 12 +50: 12 +52: 12 +54: 14 +56: 14 +58: 14 +60: 12 +62: 14 +64: 14 +66: 17 +68: 14 +72: 18 +74: 14 +76: 20 +78: 14 +82: 18 +86: 14 +90: 18 +92: 14 diff --git a/inputs/input13_test b/inputs/input13_test new file mode 100644 index 0000000..0239024 --- /dev/null +++ b/inputs/input13_test @@ -0,0 +1,4 @@ +0: 3 +1: 2 +4: 4 +6: 4