You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
848 B
40 lines
848 B
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
from copy import deepcopy
|
|
import numpy as np
|
|
|
|
def memo(f):
|
|
memo = {}
|
|
|
|
def f2(x,y):
|
|
if (x,y) not in memo: memo[(x,y)] = f(x,y)
|
|
return memo[(x,y)]
|
|
return f2
|
|
|
|
|
|
@memo
|
|
def blink(stone, i):
|
|
if i == 0: return 1
|
|
else: i -= 1
|
|
if stone == 0: return blink(1,i)
|
|
elif len(str(stone)) % 2 == 0:
|
|
ds = int(len(str(int(stone)))/2)
|
|
return(blink(int(str(int(stone))[:ds]),i) + blink(int(str(int(stone))[ds:]),i))
|
|
else: return blink(stone*2024, i)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
stones = [int(n) for n in open(sys.argv[1]).read().strip('\n').split(' ')]
|
|
|
|
res1, res2 = 0, 0
|
|
for s in stones:
|
|
res1 += blink(s, 25)
|
|
res2 += blink(s, 75)
|
|
|
|
# challenge 1
|
|
print(f"challenge 1:\n{res1}\n")
|
|
|
|
# challenge 2
|
|
print(f"challenge 2:\n{res2}")
|
|
|
|
|