-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathday11.py
executable file
·56 lines (40 loc) · 885 Bytes
/
day11.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
from utils.all import *
advent.setup(2024, 11)
fin = advent.get_input()
data = fin.read()
ints = extract_ints(data)
ans1 = ans2 = 0
def blink(ints):
new = []
for x in ints:
if x == 0:
new.append(1)
else:
n = str(x)
l = len(n)
if l % 2 == 0:
new.append(int(n[:l // 2]))
new.append(int(n[l // 2:]))
else:
new.append(x * 2024)
return new
orig_ints = ints[:]
for _ in range(25):
ints = blink(ints)
ans1 = len(ints)
advent.print_answer(1, ans1)
@lru_cache(None)
def calc(n, blinks=0, limit=75):
if blinks == limit:
return 1
if n == 0:
return calc(1, blinks + 1, limit)
s = str(n)
l = len(s)
if l % 2 == 0:
return calc(int(s[:l // 2]), blinks + 1, limit) + calc(int(s[l // 2:]), blinks + 1, limit)
return calc(n * 2024, blinks + 1, limit)
for i in orig_ints:
ans2 += calc(i)
advent.print_answer(2, ans2)