Benjamin Kraft 3 years ago
parent 593f71d9a7
commit 34d9cf0260
  1. 50
      06/06.py
  2. 1
      06/input

@ -2,32 +2,50 @@ import numpy as np
def readFish():
with open("testInput") as file:
with open("input") as file:
return np.array(file.read().split(","), dtype=np.uint8)
def getCount(fish, days):
return 0
def getCount(fish, daysLeft, usedList, usedMap):
if daysLeft <= fish:
return 1
if usedList[fish][daysLeft]:
return usedMap[(fish, daysLeft)]
count = 1
for d in range(0, daysLeft - fish, 7):
count += getCount(9, daysLeft - fish - d, usedList, usedMap)
usedList[fish][daysLeft] = True
usedMap[(fish, daysLeft)] = count
return count
def solve(days):
fish = readFish()
# need to save/read known results for performance
usedMap = {}
usedList = np.zeros((10, days + 1), bool)
fish = readFish()
count = 0
for f in fish:
count += getCount(f, 80)
count += getCount(f, days, usedList, usedMap)
# numpy version too slow for part 2
# for i in range(days):
# decrease = fish > 0
# zeros = fish == 0
# fish[decrease] -= 1
# fish[zeros] = 6
# fish = np.concatenate((fish, zeros[zeros].astype(np.uint8) * 8))
# print(i, len(fish))
for i in range(0):
decrease = fish > 0
zeros = fish == 0
fish[decrease] -= 1
fish[zeros] = 6
fish = np.concatenate((fish, zeros[zeros].astype(np.uint8) * 8))
print(i, len(fish))
return count
return len(fish)
print(solve(80))
print(solve(256))
# print(solve(80))
import cProfile
cProfile.run("print(solve(200))")

@ -0,0 +1 @@
3,5,1,2,5,4,1,5,1,2,5,5,1,3,1,5,1,3,2,1,5,1,1,1,2,3,1,3,1,2,1,1,5,1,5,4,5,5,3,3,1,5,1,1,5,5,1,3,5,5,3,2,2,4,1,5,3,4,2,5,4,1,2,2,5,1,1,2,4,4,1,3,1,3,1,1,2,2,1,1,5,1,1,4,4,5,5,1,2,1,4,1,1,4,4,3,4,2,2,3,3,2,1,3,3,2,1,1,1,2,1,4,2,2,1,5,5,3,4,5,5,2,5,2,2,5,3,3,1,2,4,2,1,5,1,1,2,3,5,5,1,1,5,5,1,4,5,3,5,2,3,2,4,3,1,4,2,5,1,3,2,1,1,3,4,2,1,1,1,1,2,1,4,3,1,3,1,2,4,1,2,4,3,2,3,5,5,3,3,1,2,3,4,5,2,4,5,1,1,1,4,5,3,5,3,5,1,1,5,1,5,3,1,2,3,4,1,1,4,1,2,4,1,5,4,1,5,4,2,1,5,2,1,3,5,5,4,5,5,1,1,4,1,2,3,5,3,3,1,1,1,4,3,1,1,4,1,5,3,5,1,4,2,5,1,1,4,4,4,2,5,1,2,5,2,1,3,1,5,1,2,1,1,5,2,4,2,1,3,5,5,4,1,1,1,5,5,2,1,1
Loading…
Cancel
Save