From 97c7b63217c71586720772462258a458c50e17a6 Mon Sep 17 00:00:00 2001 From: Thibaud Date: Fri, 5 Dec 2025 16:42:14 +0100 Subject: [PATCH] 2025 day 1 --- adventofcode/2025/day1/day1.py | 43 ++++++++++++++++++++++++++++++++++ adventofcode/aoc.py | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 adventofcode/2025/day1/day1.py diff --git a/adventofcode/2025/day1/day1.py b/adventofcode/2025/day1/day1.py new file mode 100644 index 0000000..c4ec2e8 --- /dev/null +++ b/adventofcode/2025/day1/day1.py @@ -0,0 +1,43 @@ +def part1(lines): + pos = 50 + cnt = 0 + for rotation in lines: + direction = -1 if rotation[0] == "L" else 1 + amount = int(rotation[1:]) + pos = (pos + amount * direction) % 100 + if pos == 0: + cnt += 1 + print("Part 1: ", cnt) + + + +def part2(lines): + pos = 50 + cnt = 0 + for rotation in lines: + direction = -1 if rotation[0] == "L" else 1 + amount = int(rotation[1:]) + pos0 = pos % 100 + # k0 is the smallest positive number of clicks (1..100) after the + # start of the current rotation at which the dial first reaches + # position 0. + k0 = ((100 - pos0) % 100) if direction == 1 else (pos0 % 100) + if k0 == 0: + k0 = 100 + if amount >= k0: + cnt += 1 + (amount - k0) // 100 + pos = (pos + direction * amount) % 100 + print(rotation, pos, cnt) + print("Part 2: ", cnt) + + +if __name__ == "__main__": + import sys + infile = sys.argv[1] + + with open(infile) as f: + lines = f.readlines() + lines = [x.rstrip() for x in lines] + part1(lines) + part2(lines) + diff --git a/adventofcode/aoc.py b/adventofcode/aoc.py index 3fc9343..7950359 100644 --- a/adventofcode/aoc.py +++ b/adventofcode/aoc.py @@ -14,7 +14,7 @@ def main(): # Sous-commande run run_parser = subparsers.add_parser('run', help='Run an aoc day') run_parser.add_argument('year', type=int) - run_parser.add_argument('day', type=int) + run_parser.add_argument('day', type=int, nargs='?', default=None) args = parser.parse_args()