aboutsummaryrefslogtreecommitdiff
path: root/2025/02
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-12-02 06:15:47 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2025-12-02 06:37:33 +0100
commitc0c0f809bb5b2327db96c7dbb5e9ef8ea5960b00 (patch)
treef0ae0f3e09b748aafb3effba7051eb8e136c55e1 /2025/02
parent8e716a225ece98cf75cc1789c8f90757c0beadfc (diff)
downloadaoc-c0c0f809bb5b2327db96c7dbb5e9ef8ea5960b00.tar.gz
aoc-c0c0f809bb5b2327db96c7dbb5e9ef8ea5960b00.zip
Day 2 2025 (solved part 2 before part 1 because I misread lol)
Diffstat (limited to '2025/02')
-rw-r--r--2025/02/a.py13
-rw-r--r--2025/02/b.py25
2 files changed, 37 insertions, 1 deletions
diff --git a/2025/02/a.py b/2025/02/a.py
index 5fdb11b..9c6fd84 100644
--- a/2025/02/a.py
+++ b/2025/02/a.py
@@ -1,6 +1,17 @@
1import fileinput 1import fileinput
2 2
3def invalid(n):
4 return n[:len(n)//2] == n[len(n)//2:]
5
6s = 0
3with fileinput.input() as lines: 7with fileinput.input() as lines:
4 for line in lines: 8 for line in lines:
5 ... 9 for r in line.split(","):
10 l = r.split("-");
11 for n in range(int(l[0]), int(l[1])+1):
12 if invalid(str(n)):
13 print(n)
14 s += n
15print(s)
16
6 17
diff --git a/2025/02/b.py b/2025/02/b.py
new file mode 100644
index 0000000..8efdbe3
--- /dev/null
+++ b/2025/02/b.py
@@ -0,0 +1,25 @@
1import fileinput
2
3def invk(n, k):
4 for i in range(0, len(n)-k, k):
5 if n[i:i+k] != n[i+k:i+2*k]:
6 return False
7 return True
8
9def invalid(n):
10 for k in range(1, len(n)//2 + 1):
11 if invk(n, k):
12 return True
13 return False
14
15s = 0
16with fileinput.input() as lines:
17 for line in lines:
18 for r in line.split(","):
19 l = r.split("-");
20 for n in range(int(l[0]), int(l[1])+1):
21 if invalid(str(n)):
22 s += n
23print(s)
24
25

Generated with cgit - Back to sebastiano.tronto.net