Skip to content

Commit 5eb6225

Browse files
authored
Merge pull request #20 from B-AROL-O/gmacario-dev
feat: add gmacario+gpt-oss-120 solutions to aoc-2025 days 04-09
2 parents c4f7a67 + 9c36f26 commit 5eb6225

22 files changed

Lines changed: 3420 additions & 12 deletions

2025/gmacario/day00/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Boilerplate for AoC-2025 daily solver
2+
3+
Perform the following steps:
4+
5+
1. Copy `day00` to the desired day `daynn`
6+
2. Rename `solve_day00.py` to `solve_daynn.py`
7+
3. Rename `sample_day00.txt` to `sample_daynn.txt`
8+
4. Copy the text of Day _nn_ challenge into `README.md`. Make sure to correct Markdown formatting
9+
5. Copy the sample input for Day _nn_ challenge into `sample_daynn.txt`
10+
6. Fetch the actual input into `input_daynn.txt`
11+
7. Read and understand `README.md`
12+
8. Adjust `solve_daynn.py` accordingly
13+
9. Test the solution to Part 1 of the challenge:
14+
15+
```bash
16+
uv run daynn/solve_daynn.py
17+
```
18+
19+
10. Ensure that the solution to `sample_daynn.txt` matches the one in the `README.md`
20+
11. Repeat steps 7-10 until the solution to Part 1 passes with the sample data
21+
12. Uncomment line 10 of `solve_daynn.py`, then run the solver against `input_daynn.txt`
22+
23+
```bash
24+
uv run daynn/solve_daynn.py
25+
```
26+
27+
13. Paste the value in line `INFO: Daynn solve_part1 result: xxx` into the text field of AoC-2025 Day _nn_ challenge
28+
14. If everything works, do a `git commit` with the working changes, then proceed to solving Part 2
29+
15. Comment line 10 of `solve_daynn.py`
30+
16. Update `README.md` with the text for Part 2 of the challenge
31+
17. Repeat steps 7-12 until Part 2 is solved
32+
18. If everything works, do a `git commit` with the working changes
33+
19. Update the code until all Super-Linter checks are green
34+
20. Create a Pull Request against <https://github.com/B-AROL-O/advent-of-code>
35+
36+
<!-- EOF -->
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO
Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
from icecream import ic
44

5+
CHALLENGE_YEAR = 2025
56
CHALLENGE_DAY = 0
67

7-
CHALLENGE_URL = f"https://adventofcode.com/2025/day/{CHALLENGE_DAY}"
8+
CHALLENGE_URL = f"https://adventofcode.com/{CHALLENGE_YEAR}/day/{CHALLENGE_DAY}"
89
INPUT_FILE = f"day{CHALLENGE_DAY:02}/sample_day{CHALLENGE_DAY:02}.txt"
910
# INPUT_FILE=f"day{CHALLENGE_DAY:02}/input_day{CHALLENGE_DAY:02}.txt"
1011

11-
print(f"INFO: Advent of Code 2025 - Day {CHALLENGE_DAY}")
12+
print(f"INFO: Advent of Code {CHALLENGE_YEAR} - Day {CHALLENGE_DAY}")
1213
print(f"INFO: URL: {CHALLENGE_URL}")
1314
print(f"INFO: INPUT_FILE: {INPUT_FILE}")
1415

@@ -21,11 +22,58 @@
2122
ic(input_lines)
2223

2324

25+
"""
26+
Credits: TODO
27+
28+
Prompt:
29+
30+
Solve Part One of the following challenge by creating a Python function with the following signature:
31+
32+
```python
33+
def solve_part1_with_ai(input_lines: List[str]) -> int
34+
```
35+
36+
where `input_lines` is a list of string produced by reading the input file as per the provided example:
37+
38+
Make sure you get the same result as shown in the example.
39+
40+
Here is the full text of the challenge:
41+
42+
(paste contents of day09/README.md)
43+
"""
44+
# def solve_part1_with_ai(input_lines: List[str]) ->int:
45+
# pass # TODO
46+
47+
48+
"""
49+
Credits: TODO
50+
51+
Prompt:
52+
53+
Solve Part Two of the following challenge by creating a Python function with the following signature:
54+
55+
```python
56+
def solve_part2_with_ai(input_lines: List[str]) -> int
57+
```
58+
59+
where `input_lines` is a list of string produced by reading the input file as per the provided example:
60+
61+
Make sure you get the same result as shown in the example.
62+
63+
Here is the full text of the challenge:
64+
65+
(paste contents of day00/README.md)
66+
"""
67+
# def solve_part2_with_ai(input_lines: List[str]) ->int:
68+
# pass # TODO
69+
70+
2471
def solve_part1():
2572
tm_start = time.time()
2673
result_part1 = 0
2774

2875
ic("DEBUG: TODO solve_part1()")
76+
# result_part1 = solve_part1_with_ai(input_lines)
2977

3078
tm_end = time.time()
3179
print(f"DEBUG: solve_part1 Begin: {time.ctime(tm_start)}")
@@ -40,6 +88,7 @@ def solve_part2():
4088
result_part2 = 0
4189

4290
ic("DEBUG: TODO solve_part2()")
91+
# result_part2 = solve_part2_with_ai(input_lines)
4392

4493
tm_end = time.time()
4594
print(f"DEBUG: solve_part2 Begin: {time.ctime(tm_start)}")
@@ -51,9 +100,6 @@ def solve_part2():
51100

52101
if __name__ == "__main__":
53102
solve_part1()
54-
# check_valid_id_part2("1010")
55-
# check_valid_id_part2("1011")
56103
solve_part2()
57-
pass
58104

59105
# EOF

2025/gmacario/day04/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# --- Day 4: Printing Department ---
22

3-
<>
3+
<https://adventofcode.com/2025/day/4>
44

55
You ride the escalator down to the printing department. They're clearly getting ready for Christmas; they have lots of large rolls of paper everywhere, and there's even a massive printer in the corner (to handle the really big print jobs).
66

2025/gmacario/day04/solve_day04.py

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import time
22

3-
from icecream import ic
3+
from collections import deque
4+
from typing import Deque, List, Tuple
5+
6+
# from icecream import ic
47

58
CHALLENGE_DAY = 4
69

@@ -21,6 +24,90 @@
2124
# ic(input_lines)
2225

2326

27+
"""
28+
Credits: <https://openwebui.gmacario.it/c/c19b36fc-d4fe-4bdc-9ca9-f6b178edf237>
29+
30+
Prompt:
31+
32+
Solve Part Two of the following challenge by creating a Python function with the following signature:
33+
34+
```python
35+
def solve_part2_with_ai(input_lines: List[str]) -> int
36+
```
37+
38+
where `input_lines` is a list of string produced by reading the input file as per the provided example:
39+
40+
(paste contents of day04/sample_day04.txt)
41+
42+
Here is the full text of the challenge:
43+
44+
(paste contents of day04/README.md)
45+
"""
46+
def solve_part2_with_ai(input_lines: List[str]) -> int:
47+
"""
48+
Implements the Part 2 solution described above.
49+
Returns the total number of '@' cells that can be removed.
50+
"""
51+
if not input_lines:
52+
return 0
53+
54+
rows = len(input_lines)
55+
cols = len(input_lines[0])
56+
57+
# 1. parse the grid
58+
paper = [[c == '@' for c in line] for line in input_lines]
59+
60+
# 2. auxiliary structures
61+
removed = [[False] * cols for _ in range(rows)]
62+
deg = [[0] * cols for _ in range(rows)]
63+
64+
# 8 possible neighbour offsets
65+
neigh_offsets = [(-1, -1), (-1, 0), (-1, 1),
66+
(0, -1), (0, 1),
67+
(1, -1), (1, 0), (1, 1)]
68+
69+
# 3. initial degree computation
70+
for i in range(rows):
71+
for j in range(cols):
72+
if not paper[i][j]:
73+
continue
74+
cnt = 0
75+
for di, dj in neigh_offsets:
76+
ni, nj = i + di, j + dj
77+
if 0 <= ni < rows and 0 <= nj < cols and paper[ni][nj]:
78+
cnt += 1
79+
deg[i][j] = cnt
80+
81+
# 4. initialise queue with cells of degree < 4
82+
q: Deque[Tuple[int, int]] = deque()
83+
for i in range(rows):
84+
for j in range(cols):
85+
if paper[i][j] and deg[i][j] < 4:
86+
q.append((i, j))
87+
88+
removed_cnt = 0
89+
90+
# 5. iterative removal
91+
while q:
92+
i, j = q.popleft()
93+
if removed[i][j]:
94+
continue # may have been queued earlier
95+
removed[i][j] = True
96+
removed_cnt += 1
97+
98+
# decrease degree of still‑present neighbours
99+
for di, dj in neigh_offsets:
100+
ni, nj = i + di, j + dj
101+
if 0 <= ni < rows and 0 <= nj < cols:
102+
if paper[ni][nj] and not removed[ni][nj]:
103+
deg[ni][nj] -= 1
104+
# we only need to enqueue when it just crossed the threshold
105+
if deg[ni][nj] == 3:
106+
q.append((ni, nj))
107+
108+
return removed_cnt
109+
110+
24111
def solve_part1():
25112
tm_start = time.time()
26113
# result_part1 = 0
@@ -87,7 +174,8 @@ def solve_part2():
87174
tm_start = time.time()
88175
result_part2 = 0
89176

90-
ic("DEBUG: TODO solve_part2()")
177+
# ic("DEBUG: TODO solve_part2()")
178+
result_part2 = solve_part2_with_ai(input_lines)
91179

92180
tm_end = time.time()
93181
print(f"DEBUG: solve_part2 Begin: {time.ctime(tm_start)}")

2025/gmacario/day05/solve_day05.py

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import time
22

3-
from icecream import ic
3+
from typing import List
4+
5+
# from icecream import ic
46

57
CHALLENGE_DAY = 5
68

@@ -40,6 +42,67 @@
4042
# ic(available_ingredients)
4143

4244

45+
"""
46+
Credits: <https://openwebui.gmacario.it/c/aa5b67d6-ccb6-4b66-a94f-914f2ba46d67>
47+
48+
Prompt:
49+
50+
Solve Part Two of the following challenge by creating a Python function with the following signature:
51+
52+
```python
53+
def solve_part2_with_ai(input_lines: List[str]) -> int
54+
```
55+
56+
where `input_lines` is a list of string produced by reading the input file as per the provided example:
57+
58+
(paste contents of day05/sample_day07.txt)
59+
60+
Here is the full text of the challenge:
61+
62+
(paste contents of day05/README.md)
63+
"""
64+
def solve_part2_with_ai(input_lines: List[str]) -> int:
65+
"""
66+
Counts how many distinct integer IDs are covered by the fresh‑ID ranges
67+
appearing before the first blank line of the input.
68+
"""
69+
# -----------------------------------------------------------------
70+
# 1. read the ranges (stop at the first blank line)
71+
ranges = []
72+
for line in input_lines:
73+
if line.strip() == "":
74+
break
75+
low_str, high_str = line.split('-')
76+
low, high = int(low_str), int(high_str)
77+
ranges.append((low, high))
78+
79+
if not ranges: # no ranges at all
80+
return 0
81+
82+
# -----------------------------------------------------------------
83+
# 2. sort by lower bound
84+
ranges.sort(key=lambda p: p[0])
85+
86+
# 3. merge overlapping / adjacent intervals
87+
merged = []
88+
cur_low, cur_high = ranges[0]
89+
90+
for low, high in ranges[1:]:
91+
if low <= cur_high + 1: # overlap or directly adjacent
92+
if high > cur_high:
93+
cur_high = high
94+
else:
95+
merged.append((cur_low, cur_high))
96+
cur_low, cur_high = low, high
97+
98+
merged.append((cur_low, cur_high)) # add the last interval
99+
100+
# -----------------------------------------------------------------
101+
# 4. sum their lengths
102+
total = sum(high - low + 1 for low, high in merged)
103+
return total
104+
105+
43106
def solve_part1():
44107
tm_start = time.time()
45108
result_part1 = 0
@@ -67,7 +130,8 @@ def solve_part2():
67130
tm_start = time.time()
68131
result_part2 = 0
69132

70-
ic("DEBUG: TODO solve_part2()")
133+
# ic("DEBUG: TODO solve_part2()")
134+
result_part2 = solve_part2_with_ai(input_lines)
71135

72136
tm_end = time.time()
73137
print(f"DEBUG: solve_part2 Begin: {time.ctime(tm_start)}")
@@ -79,8 +143,6 @@ def solve_part2():
79143

80144
if __name__ == "__main__":
81145
solve_part1()
82-
# check_valid_id_part2("1010")
83-
# check_valid_id_part2("1011")
84146
solve_part2()
85147
pass
86148

2025/gmacario/day06/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# --- Day 6: Trash Compactor ---
2+
3+
After helping the Elves in the kitchen, you were taking a break and helping them re-enact a movie scene when you over-enthusiastically jumped into the garbage chute!
4+
5+
A brief fall later, you find yourself in a garbage smasher. Unfortunately, the door's been magnetically sealed.
6+
7+
As you try to find a way out, you are approached by a family of cephalopods! They're pretty sure they can get the door open, but it will take some time. While you wait, they're curious if you can help the youngest cephalopod with her [math homework](https://adventofcode.com/2021/day/18).
8+
9+
Cephalopod math doesn't look that different from normal math. The math worksheet (your puzzle input) consists of a list of _problems_; each problem has a group of numbers that need to either be either _added_ (`+`) or _multiplied_ (`*`) together.
10+
11+
However, the problems are arranged a little strangely; they seem to be presented next to each other in a very long horizontal list. For example:
12+
13+
```text
14+
123 328 51 64
15+
45 64 387 23
16+
6 98 215 314
17+
* + * +
18+
```
19+
20+
Each problem's numbers are arranged vertically; at the bottom of the problem is the symbol for the operation that needs to be performed. Problems are separated by a full column of only spaces. The left/right alignment of numbers within each problem can be ignored.
21+
22+
So, this worksheet contains four problems:
23+
24+
- `123` \* `45` \* `6` = _`33210`_
25+
- `328` + `64` + `98` = _`490`_
26+
- `51` \* `387` \* `215` = _`4243455`_
27+
- `64` + `23` + `314` = _`401`_
28+
29+
To check their work, cephalopod students are given the _grand total_ of adding together all of the answers to the individual problems. In this worksheet, the grand total is `33210` + `490` + `4243455` + `401` = _`4277556`_.
30+
31+
Of course, the actual worksheet is _much_ wider. You'll need to make sure to unroll it completely so that you can read the problems clearly.
32+
33+
Solve the problems on the math worksheet. _What is the grand total found by adding together all of the answers to the individual problems?_
34+
35+
To begin, [get your puzzle input](https://adventofcode.com/2025/day/6/input).
36+
37+
Answer: TODO
38+
39+
You can also \[Share\] this puzzle.
40+
41+
<!-- EOF -->

0 commit comments

Comments
 (0)