diff options
| author | nekineki <nekineki@nekineki.net> | 2025-12-02 11:24:17 +0100 |
|---|---|---|
| committer | nekineki <nekineki@nekineki.net> | 2025-12-02 11:24:17 +0100 |
| commit | 270a0b0712310b5b8f0442d21101115c6e2a117c (patch) | |
| tree | fe25349ea8ee09767853d6265bbed8ff1e114feb | |
| parent | 43ec4acd98ddf8c3b13bc34a61c8f8a807f5473f (diff) | |
day02
| -rwxr-xr-x | 2025/day02.py | 47 | ||||
| -rw-r--r-- | 2025/in/day02.pzl | 1 | ||||
| -rw-r--r-- | 2025/in/day02.ref | 1 |
3 files changed, 49 insertions, 0 deletions
diff --git a/2025/day02.py b/2025/day02.py new file mode 100755 index 0000000..552d5b9 --- /dev/null +++ b/2025/day02.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +from functools import reduce +from re import findall +from copy import deepcopy +import sys +# import numpy as np + +filename = sys.argv[1] if len(sys.argv) == 2 \ + else "in/" + sys.argv[0].split('/')[-1].rstrip(".py") + ".pzl" +data = open(filename).read() +lines = data.rstrip('\n').split('\n') + +res1 = 0 +res2 = 0 + +def check1(a): + a = str(a) + l = len(a) + if l % 2 != 0: + return False + if a[0:l//2] == a[l//2:]: + return True + return False + +def check2(a): + a = str(a) + l = len(a) + for n in range(1, l): + aa = [a[i:i+n] for i in range(0, l, n)] + if len(a) > 1 and len(set(aa)) == 1: + return True + return False + +line = lines[0] +for seq in line.split(','): + a, b = seq.split('-') + a, b = int(a), int(b) + print(b - a) + for i in range(a, b+1): + if check1(i): + res1 += i + if check2(i): + res2 += i + +print('res1:', res1) +print('res2:', res2) + diff --git a/2025/in/day02.pzl b/2025/in/day02.pzl new file mode 100644 index 0000000..a5f0835 --- /dev/null +++ b/2025/in/day02.pzl @@ -0,0 +1 @@ +2157315-2351307,9277418835-9277548385,4316210399-4316270469,5108-10166,872858020-872881548,537939-575851,712-1001,326613-416466,53866-90153,907856-1011878,145-267,806649-874324,6161532344-6161720341,1-19,543444404-543597493,35316486-35418695,20-38,84775309-84908167,197736-309460,112892-187377,336-552,4789179-4964962,726183-793532,595834-656619,1838-3473,3529-5102,48-84,92914229-92940627,65847714-65945664,64090783-64286175,419838-474093,85-113,34939-52753,14849-30381 diff --git a/2025/in/day02.ref b/2025/in/day02.ref new file mode 100644 index 0000000..a3f22ef --- /dev/null +++ b/2025/in/day02.ref @@ -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 |
