From 000faf832bdbe55efac2cd4e7bad9ee11cd1e8ff Mon Sep 17 00:00:00 2001 From: kleph Date: Tue, 2 Dec 2025 18:15:41 +0100 Subject: [PATCH] 2025 - Day 2 part 1 --- 2025/2/2.py | 32 ++++++++++++++++++++++++++++++++ 2025/2/input.txt | 1 + 2025/2/input_example.txt | 1 + 3 files changed, 34 insertions(+) create mode 100644 2025/2/2.py create mode 100644 2025/2/input.txt create mode 100644 2025/2/input_example.txt diff --git a/2025/2/2.py b/2025/2/2.py new file mode 100644 index 0000000..3f1929c --- /dev/null +++ b/2025/2/2.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +# 2025 - Advent Of Code 2 + +# file = 'input_example.txt' +file = 'input.txt' + +ranges = [] +bad_id = [] +with open(file, encoding="utf-8") as f: + for line in f.readlines(): + for r in line.split(','): + (startr, endr) = r.split('-') + for i in range(int(startr), int(endr)+1): + ranges.append(str(i)) + +print(f"ranges to inspect {len(ranges)}") +# print(ranges) + +for product_id in ranges: + if len(product_id) % 2 == 1: + continue + half = int(len(product_id) / 2) + bad = True + for cursor in range(0, half): + if product_id[cursor] != product_id[half + cursor]: + bad = False + break + if bad: + bad_id.append(int(product_id)) + +# print(bad_id) +print(sum(bad_id)) diff --git a/2025/2/input.txt b/2025/2/input.txt new file mode 100644 index 0000000..0acf68b --- /dev/null +++ b/2025/2/input.txt @@ -0,0 +1 @@ +245284-286195,797927-983972,4949410945-4949555758,115-282,8266093206-8266228431,1-21,483873-655838,419252-466133,6190-13590,3876510-4037577,9946738680-9946889090,99954692-100029290,2398820-2469257,142130432-142157371,9797879567-9798085531,209853-240025,85618-110471,35694994-35766376,4395291-4476150,33658388-33694159,680915-772910,4973452995-4973630970,52-104,984439-1009605,19489345-19604283,22-42,154149-204168,7651663-7807184,287903-402052,2244-5558,587557762-587611332,307-1038,16266-85176,422394377-422468141 diff --git a/2025/2/input_example.txt b/2025/2/input_example.txt new file mode 100644 index 0000000..a3f22ef --- /dev/null +++ b/2025/2/input_example.txt @@ -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