Compare commits
2 Commits
ad6279089f
...
eec175943e
Author | SHA1 | Date | |
---|---|---|---|
eec175943e | |||
0e13af40c5 |
1
day11/input
Normal file
1
day11/input
Normal file
@ -0,0 +1 @@
|
||||
6563348 67 395 0 6 4425 89567 739318
|
20
day11/sample1.in
Normal file
20
day11/sample1.in
Normal file
@ -0,0 +1,20 @@
|
||||
Initial arrangement:
|
||||
125 17
|
||||
|
||||
After 1 blink:
|
||||
253000 1 7
|
||||
|
||||
After 2 blinks:
|
||||
253 0 2024 14168
|
||||
|
||||
After 3 blinks:
|
||||
512072 1 20 24 28676032
|
||||
|
||||
After 4 blinks:
|
||||
512 72 2024 2 0 2 4 2867 6032
|
||||
|
||||
After 5 blinks:
|
||||
1036288 7 2 20 24 4048 1 4048 8096 28 67 60 32
|
||||
|
||||
After 6 blinks:
|
||||
2097446912 14168 4048 2 0 2 4 40 48 2024 40 48 80 96 2 8 6 7 6 0 3 2
|
46
day11/sol.py
Normal file
46
day11/sol.py
Normal file
@ -0,0 +1,46 @@
|
||||
def solve(file):
|
||||
nums = file.read().split()
|
||||
|
||||
for i in range(25):
|
||||
if len(nums) < 100:
|
||||
print(i, nums)
|
||||
new = []
|
||||
for n in nums:
|
||||
if n == '0':
|
||||
new.append('1')
|
||||
elif len(n)%2 == 0:
|
||||
new.append(n[:len(n)//2])
|
||||
new.append(n[len(n)//2:].lstrip('0') or '0')
|
||||
else:
|
||||
new.append(str(int(n)*2024))
|
||||
nums = new
|
||||
print(len(nums))
|
||||
|
||||
def solve2(file):
|
||||
nums = file.read().split()
|
||||
|
||||
print(sum(evolve(n, 25) for n in nums))
|
||||
print(sum(evolve(n, 75) for n in nums))
|
||||
|
||||
book = {}
|
||||
def evolve(n, t):
|
||||
if t == 0:
|
||||
return 1
|
||||
elif (n,t) in book:
|
||||
return book[n,t]
|
||||
else:
|
||||
if n == '0':
|
||||
x = evolve('1', t-1)
|
||||
elif len(n)%2 == 0:
|
||||
x = evolve(n[:len(n)//2], t-1)
|
||||
x += evolve(n[len(n)//2:].lstrip('0') or '0', t-1)
|
||||
else:
|
||||
x = evolve(str(int(n)*2024), t-1)
|
||||
book[n,t] = x
|
||||
return x
|
||||
|
||||
from io import StringIO
|
||||
#solve(StringIO("0 1 10 99 999"))
|
||||
solve2(StringIO("0 1 10 99 999"))
|
||||
#solve(open("input"))
|
||||
solve2(open("input"))
|
Loading…
x
Reference in New Issue
Block a user