Compare commits

...

2 Commits

Author SHA1 Message Date
ba25ae677a Solve 2025 day 3 and 4 2026-01-11 10:33:07 -05:00
e5421854a9 Do day 3 and 4 for 2025 2025-12-26 20:18:44 -05:00
4 changed files with 74 additions and 1 deletions

34
2025/d03.py Normal file
View File

@@ -0,0 +1,34 @@
from lib import get_data
data = get_data(__file__)
def max_joltage(xs: str, target_len: int) -> int:
def dynamic(xs: str) -> dict[int, str]:
if len(xs) == 0:
return {0: ""}
rs = dynamic(xs[1:])
for i in range(target_len, 0, -1):
if not (i - 1) in rs:
continue
nv = int(xs[0] + rs[i - 1])
if not i in rs:
rs[i] = str(nv)
elif nv > int(rs[i]):
rs[i] = str(nv)
return rs
rs = dynamic(xs)
return int(rs[target_len])
r1 = 0
r2 = 0
for line in data.splitlines():
r1 += max_joltage(line, 2)
r2 += max_joltage(line, 12)
print(r1)
print(r2)

32
2025/d04.py Normal file
View File

@@ -0,0 +1,32 @@
from lib import get_data, Grid2D
data = get_data(__file__)
g = Grid2D(data)
r = 0
adjs = []
for pos in g.all_coords():
if g[pos] != "@":
continue
nr_of_rolls_adj = len([nb for nb in g.neighbors_adj(pos) if g[nb] == "@"])
if nr_of_rolls_adj < 4:
r += 1
adjs.append(pos)
print(r)
r = 0
while True:
adjs = []
for pos in g.all_coords():
if g[pos] != "@":
continue
nr_of_rolls_adj = len([nb for nb in g.neighbors_adj(pos) if g[nb] == "@"])
if nr_of_rolls_adj < 4:
adjs.append(pos)
if adjs:
r += len(adjs)
for a in adjs:
g[a] = "."
else:
break
print(r)

4
2025/d05.py Normal file
View File

@@ -0,0 +1,4 @@
from lib import get_data, Grid2D
data = get_data(__file__)
print(data)

View File

@@ -12,7 +12,10 @@ stressful and this will actually be more fun. Thank you Eric Wastl and let's go!
ticks naively. Maybe I should revisit this. ticks naively. Maybe I should revisit this.
- Day 2: The simple direct approach with iterating over all the IDs in the - Day 2: The simple direct approach with iterating over all the IDs in the
ranges just worked okay. Not pretty but acceptable. ranges just worked okay. Not pretty but acceptable.
- Day 3: - Day 3: Fun dynamic programming problem. Part 2 took me a little too long
overall but it was fun.
- Day 4: One of the easier grid based puzzles. Less than five minutes with
existing grid library.
## AoC 2024 ## AoC 2024