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.

41 lines
646 B

3 years ago
import numpy as np
def readFish():
3 years ago
with open("input") as file:
3 years ago
return np.array(file.read().split(","), dtype=np.uint8)
3 years ago
def getCount(fish, daysLeft, usedMap):
3 years ago
if daysLeft <= fish:
return 1
3 years ago
if (fish, daysLeft) in usedMap:
3 years ago
return usedMap[(fish, daysLeft)]
count = 1
for d in range(0, daysLeft - fish, 7):
3 years ago
count += getCount(9, daysLeft - fish - d, usedMap)
3 years ago
usedMap[(fish, daysLeft)] = count
return count
3 years ago
def solve(days):
3 years ago
# need to save/read known results for performance
usedMap = {}
fish = readFish()
3 years ago
count = 0
for f in fish:
3 years ago
count += getCount(f, days, usedMap)
3 years ago
3 years ago
return count
3 years ago
3 years ago
print(solve(80))
print(solve(256))
3 years ago