From 270e9dc482e1e14891efa6413f7c5ff2b5ce77ec Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Tue, 2 Dec 2025 07:54:10 +0100 Subject: [PATCH] day02 --- day02.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++ inputs/input2 | 1 + inputs/input2_test | 1 + start_day.py | 2 +- 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 day02.py create mode 100644 inputs/input2 create mode 100644 inputs/input2_test diff --git a/day02.py b/day02.py new file mode 100644 index 0000000..7f564b7 --- /dev/null +++ b/day02.py @@ -0,0 +1,48 @@ +import math + +from tools.aoc import AOCDay +from typing import Any + + +class Day(AOCDay): + inputs = [ + [ + (1227775554, "input2_test"), + (23039913998, "input2"), + ], + [ + (4174379265, "input2_test"), + (35950619148, "input2"), + ] + ] + + def parse_input(self) -> list[tuple[int, ...]]: + return [tuple(map(int, pair.split("-"))) for pair in self.getInput().split(",")] + + def part1(self) -> Any: + ans = 0 + for low, high in self.parse_input(): + for _id in range(low, high + 1): + str_id = str(_id) + if str_id[:len(str_id) // 2] == str_id[len(str_id) // 2:]: + ans += _id + + return ans + + def part2(self) -> Any: + ans = 0 + for low, high in self.parse_input(): + for _id in range(low, high + 1): + str_id = str(_id) + for x in range(1, len(str_id) // 2 + 1): + blocks = set(str_id[i:i+x] for i in range(0, len(str_id), x)) + if len(blocks) == 1: + ans += _id + break + + return ans + + +if __name__ == '__main__': + day = Day(2025, 2) + day.run(verbose=True) diff --git a/inputs/input2 b/inputs/input2 new file mode 100644 index 0000000..853bfba --- /dev/null +++ b/inputs/input2 @@ -0,0 +1 @@ +92916254-92945956,5454498003-5454580069,28-45,4615-7998,4747396917-4747534264,272993-389376,36290651-36423050,177-310,3246326-3418616,48-93,894714-949755,952007-1003147,3-16,632-1029,420-581,585519115-585673174,1041-1698,27443-39304,71589003-71823870,97-142,2790995-2837912,579556301-579617006,653443-674678,1515120817-1515176202,13504-20701,1896-3566,8359-13220,51924-98061,505196-638209,67070129-67263432,694648-751703,8892865662-8892912125 diff --git a/inputs/input2_test b/inputs/input2_test new file mode 100644 index 0000000..bd04584 --- /dev/null +++ b/inputs/input2_test @@ -0,0 +1 @@ +11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124 \ No newline at end of file diff --git a/start_day.py b/start_day.py index 3ed2176..fa67e36 100755 --- a/start_day.py +++ b/start_day.py @@ -11,7 +11,7 @@ import webbrowser YEAR = 2025 CHARMS = { - 'Linux': '/home/pennywise/bin/pycharm', + 'Linux': '/home/sharmuth/bin/pycharm', 'Windows': r'C:\Users\pennywise\AppData\Local\JetBrains\Toolbox\scripts\pycharm.cmd' }