Compare commits
2 Commits
183f909508
...
ba25ae677a
| Author | SHA1 | Date | |
|---|---|---|---|
| ba25ae677a | |||
| e5421854a9 |
34
2025/d03.py
Normal file
34
2025/d03.py
Normal 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
32
2025/d04.py
Normal 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
4
2025/d05.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from lib import get_data, Grid2D
|
||||
|
||||
data = get_data(__file__)
|
||||
print(data)
|
||||
@@ -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.
|
||||
- Day 2: The simple direct approach with iterating over all the IDs in the
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user