Compare commits

...

3 Commits

Author SHA1 Message Date
022b95eb97 Solve 2024 day 11 2024-12-11 00:38:50 -05:00
96f15d07fc Make day 10 2024 nice 2024-12-10 20:01:11 -05:00
83fbf59bd7 Solve 2024 day 10 2024-12-10 00:24:03 -05:00
3 changed files with 69 additions and 9 deletions

26
2024/d10.py Normal file
View File

@@ -0,0 +1,26 @@
from collections import deque
from lib import Grid2D
from lib import get_data
data = get_data(__file__)
g = Grid2D(data)
p1 = 0
p2 = 0
for start in g.find("0"):
queue = deque([start])
all = set()
while queue:
node = queue.popleft()
if g[node] == "9":
all.add(node)
p2 += 1
for nb in g.neighbors_ort(node):
if int(g[node]) + 1 == int(g[nb]):
queue.append(nb)
p1 += len(all)
print(p1)
print(p2)

31
2024/d11.py Normal file
View File

@@ -0,0 +1,31 @@
from lib import get_data
from lib import ints
data = get_data(__file__)
xs = ints(data)
CACHE = {}
# I had maxsize too small at first :/
# @lru_cache(maxsize=10**12)
def apply(x, rest):
if rest == 0:
return 1
if (x, rest) in CACHE:
return CACHE[(x, rest)]
if x == 0:
r = apply(1, rest - 1)
elif len(str(x)) % 2 == 0:
sx = str(x)
a = int(sx[: len(sx) // 2])
b = int(sx[len(sx) // 2 :])
r = apply(a, rest - 1) + apply(b, rest - 1)
else:
r = apply(x * 2024, rest - 1)
CACHE[(x, rest)] = r
return r
print(sum([apply(x, 25) for x in xs]))
print(sum([apply(x, 75) for x in xs]))

View File

@@ -291,13 +291,16 @@ and focus. Of course, learning more algorithms and techniques helps.
## AoC 2024
- Day 1: `00:01:30 124 0 00:02:49 141 0`
- Day 2: `00:05:34 686 0 00:08:21 531 0`
- Day 3: `00:01:48 165 0 00:02:40 56 45`
- Day 4: `00:07:47 1101 0 00:24:07 2410 0`
- Day 5: `00:07:07 679 0 00:23:02 1998 0`
- Day 6: `00:09:43 1082 0 00:16:29 464 0`
- Day 7: `00:12:29 2058 0 00:13:08 1170 0`
- Day 8: `00:15:59 1742 0 00:26:56 2190 0`
- Day 9: `00:48:23 6055 0 01:09:38 3159 0`
- Day 1: `00:01:30 124 0 00:02:49 141 0`
- Day 2: `00:05:34 686 0 00:08:21 531 0`
- Day 3: `00:01:48 165 0 00:02:40 56 45`
- Day 4: `00:07:47 1101 0 00:24:07 2410 0`
- Day 5: `00:07:07 679 0 00:23:02 1998 0`
- Day 6: `00:09:43 1082 0 00:16:29 464 0`
- Day 7: `00:12:29 2058 0 00:13:08 1170 0`
- Day 8: `00:15:59 1742 0 00:26:56 2190 0`
- Day 9: `00:48:23 6055 0 01:09:38 3159 0`
- Day 10: `00:19:47 2976 0 00:20:47 2244 0`
- Day 11: `11 00:05:13 642 0 00:33:07 2673 0`