aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--2025/06/a.py16
-rw-r--r--2025/06/b.py32
-rw-r--r--2025/README.md16
-rw-r--r--README.md2
4 files changed, 64 insertions, 2 deletions
diff --git a/2025/06/a.py b/2025/06/a.py
index 5fdb11b..1d12e01 100644
--- a/2025/06/a.py
+++ b/2025/06/a.py
@@ -1,6 +1,20 @@
1import fileinput 1import fileinput
2from functools import reduce
3from operator import mul
2 4
5a = []
6op = []
3with fileinput.input() as lines: 7with fileinput.input() as lines:
4 for line in lines: 8 for line in lines:
5 ... 9 t = line[:-1].split(' ')
10 if t[0] == '+' or t[0] == '*':
11 op = [x for x in t if x != '']
12 else:
13 a.append([int(x) for x in t if x != ''])
6 14
15def sol(a, op, i):
16 return (sum(a[j][i] for j in range(len(a))) if op[i] == '+'
17 else reduce(mul, (a[j][i] for j in range(len(a))), 1))
18
19
20print(sum(sol(a, op, i) for i in range(len(a[0]))))
diff --git a/2025/06/b.py b/2025/06/b.py
new file mode 100644
index 0000000..d52560f
--- /dev/null
+++ b/2025/06/b.py
@@ -0,0 +1,32 @@
1import fileinput
2from functools import reduce
3from operator import mul
4
5with fileinput.input() as lines:
6 all = list(lines)
7 a = [line[:-1] for line in all[:-1]]
8 op = all[-1][:-1]
9
10def sol(a, j, k):
11 nums = []
12 i = k-2
13 while i >= j:
14 n = 0
15 for r in a:
16 if r[i] != ' ':
17 n = 10*n + int(r[i])
18 nums.append(n)
19 i -= 1
20 return sum(nums) if op[j] == '+' else reduce(mul, nums, 1)
21
22j = 0
23s = 0
24while j < len(op):
25 k = j+1
26 while k < len(op) and op[k] == ' ':
27 k += 1
28 if k >= len(op):
29 k = max(len(r) for r in a)+1
30 s += sol(a, j, k)
31 j = k
32print(s)
diff --git a/2025/README.md b/2025/README.md
index a77c168..548deb3 100644
--- a/2025/README.md
+++ b/2025/README.md
@@ -11,6 +11,7 @@ Example
11 11
12``` 12```
13Day -Part 1- -Part 2- 13Day -Part 1- -Part 2-
14 6 00:13:38 01:49:24
14 5 00:04:39 00:22:19 15 5 00:04:39 00:22:19
15 4 00:25:36 00:27:49 16 4 00:25:36 00:27:49
16 3 00:05:02 00:16:09 17 3 00:05:02 00:16:09
@@ -69,3 +70,18 @@ Part 2 required a little bit of thinking to handle overlaps correctly
69- at first I wrote a solution that did not handle overlaps, then one 70- at first I wrote a solution that did not handle overlaps, then one
70that can only handle single overlaps, and finally one that works in 71that can only handle single overlaps, and finally one that works in
71every case. My final solution is quite straightforward. 72every case. My final solution is quite straightforward.
73
74### Day 6: Trash Compactor
75
76Part 1 was easy, but I struggled with part 2.
77
78I had to solve this while travelling, which did not help, but that was
79not the main issue. The problem was that for whatever reason my script
80did not copy the whitespaces correctly from the sample input in the web
81page, so I was left wondering how the heck am I supposed to align the
82numbers. After more than an hour and after changing train, I figured out
83the error and I was able to solve this elementary school problem. Much
84smart, very accomplishment.
85
86This year so far the only problems that took me more than 30 minutes
87are this and the first one, not exactly the hardest problems imaginable.
diff --git a/README.md b/README.md
index 33cafd8..8b83987 100644
--- a/README.md
+++ b/README.md
@@ -14,4 +14,4 @@ See `year/README.md` for instructions on how to run my code.
14|2022| 50 | Rust | Done in 2025 to learn Rust | 14|2022| 50 | Rust | Done in 2025 to learn Rust |
15|2023| 50 | C | All solved by December 25, 2023 | 15|2023| 50 | C | All solved by December 25, 2023 |
16|2024| 50 | C++ | Each solved within 24h | 16|2024| 50 | C++ | Each solved within 24h |
17|2025| 10 | Python | Work in progress... | 17|2025| 12 | Python | Work in progress... |

Generated with cgit - Back to sebastiano.tronto.net