From 6e40549618390289d17ef81cf14861da5b282698 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Mon, 30 Dec 2024 12:12:54 +0100 Subject: [PATCH] day15 --- day15.py | 42 ++++++++++++++++++++++++++++++++++++++++++ inputs/input15 | 6 ++++++ inputs/input15_test | 2 ++ start_day.py | 2 +- 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 day15.py create mode 100644 inputs/input15 create mode 100644 inputs/input15_test mode change 100644 => 100755 start_day.py diff --git a/day15.py b/day15.py new file mode 100644 index 0000000..8df607a --- /dev/null +++ b/day15.py @@ -0,0 +1,42 @@ +from tools.aoc import AOCDay +from typing import Any + +def solve(disks: list[tuple[int, int, int]]) -> int: + time = 0 + while not all((time + disk_id + cur_pos) % num_pos == 0 for disk_id, num_pos, cur_pos in disks): + time += 1 + + return time + + +class Day(AOCDay): + inputs = [ + [ + (5, "input15_test"), + (376777, "input15"), + ], + [ + (3903937, "input15"), + ] + ] + + def parse_input(self) -> list[tuple[int, int, int]]: + disks = [] + for disk in self.getIntsFromInput(): + disks.append((disk[0], disk[1], disk[3])) + + return disks + + def part1(self) -> Any: + disks = self.parse_input() + return solve(disks) + + def part2(self) -> Any: + disks = self.parse_input() + disks = disks + [(len(disks) + 1, 11, 0)] + return solve(disks) + + +if __name__ == '__main__': + day = Day(2016, 15) + day.run(verbose=True) diff --git a/inputs/input15 b/inputs/input15 new file mode 100644 index 0000000..1f25755 --- /dev/null +++ b/inputs/input15 @@ -0,0 +1,6 @@ +Disc #1 has 13 positions; at time=0, it is at position 1. +Disc #2 has 19 positions; at time=0, it is at position 10. +Disc #3 has 3 positions; at time=0, it is at position 2. +Disc #4 has 7 positions; at time=0, it is at position 1. +Disc #5 has 5 positions; at time=0, it is at position 3. +Disc #6 has 17 positions; at time=0, it is at position 5. diff --git a/inputs/input15_test b/inputs/input15_test new file mode 100644 index 0000000..b65eea1 --- /dev/null +++ b/inputs/input15_test @@ -0,0 +1,2 @@ +Disc #1 has 5 positions; at time=0, it is at position 4. +Disc #2 has 2 positions; at time=0, it is at position 1. \ No newline at end of file diff --git a/start_day.py b/start_day.py old mode 100644 new mode 100755 index 99f5505..1cc1de2 --- a/start_day.py +++ b/start_day.py @@ -11,7 +11,7 @@ import webbrowser YEAR = 2016 CHARMS = { - 'Linux': '/usr/local/bin/charm', + 'Linux': '~/.local/share/JetBrains/Toolbox/scripts/pycharm', 'Windows': r'C:\Users\pennywise\AppData\Local\JetBrains\Toolbox\scripts\pycharm.cmd' }