day 11 part 2
parent
0e13af40c5
commit
eec175943e
29
day11/sol.py
29
day11/sol.py
|
@ -16,6 +16,31 @@ def solve(file):
|
||||||
nums = new
|
nums = new
|
||||||
print(len(nums))
|
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
|
from io import StringIO
|
||||||
solve(StringIO("0 1 10 99 999"))
|
#solve(StringIO("0 1 10 99 999"))
|
||||||
solve(open("input"))
|
solve2(StringIO("0 1 10 99 999"))
|
||||||
|
#solve(open("input"))
|
||||||
|
solve2(open("input"))
|
||||||
|
|
Loading…
Reference in New Issue