From 9a5897748b8575458c63d6a48dc9f871524ae4b0 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Sat, 3 Dec 2022 10:23:57 +0100 Subject: [PATCH] day17 --- day17.py | 40 ++++++++++++++++++++++++++++++++++++++++ inputs/input17 | 1 + inputs/input17_test | 1 + 3 files changed, 42 insertions(+) create mode 100644 day17.py create mode 100644 inputs/input17 create mode 100644 inputs/input17_test diff --git a/day17.py b/day17.py new file mode 100644 index 0000000..54a30fb --- /dev/null +++ b/day17.py @@ -0,0 +1,40 @@ +from tools.aoc import AOCDay +from typing import Any + + +class Day(AOCDay): + inputs = [ + [ + (638, "input17_test"), + (1506, "input17"), + ], + [ + (39479736, "input17") + ] + ] + + def part1(self) -> Any: + step = self.getInput(int) + buffer = [0] + index = 0 + for i in range(2017): + index = (index + step) % len(buffer) + 1 + buffer.insert(index, i + 1) + + return buffer[buffer.index(2017) + 1] + + def part2(self) -> Any: + step = self.getInput(int) + index = 0 + ans = 0 + for i in range(50_000_000): + index = (index + step) % (i + 1) + 1 + if index == 1: + ans = i + 1 + + return ans + + +if __name__ == '__main__': + day = Day(2017, 17) + day.run(verbose=True) diff --git a/inputs/input17 b/inputs/input17 new file mode 100644 index 0000000..cf7ff50 --- /dev/null +++ b/inputs/input17 @@ -0,0 +1 @@ +359 diff --git a/inputs/input17_test b/inputs/input17_test new file mode 100644 index 0000000..e440e5c --- /dev/null +++ b/inputs/input17_test @@ -0,0 +1 @@ +3 \ No newline at end of file