my advent of code 2021 solutions
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.

42 lines
1.4 KiB

#inp = [3,4,3,1,2]
inp = [1,4,1,1,1,1,5,1,1,5,1,4,2,5,1,2,3,1,1,1,1,5,4,2,1,1,3,1,1,1,1,1,1,1,2,1,1,1,1,1,5,1,1,1,1,1,1,1,1,1,4,1,1,1,1,5,1,4,1,1,4,1,1,1,1,4,1,1,5,5,1,1,1,4,1,1,1,1,1,3,2,1,1,1,1,1,2,3,1,1,2,1,1,1,3,1,1,1,2,1,2,1,1,2,1,1,3,1,1,1,3,3,5,1,4,1,1,5,1,1,4,1,5,3,3,5,1,1,1,4,1,1,1,1,1,1,5,5,1,1,4,1,2,1,1,1,1,2,2,2,1,1,2,2,4,1,1,1,1,3,1,2,3,4,1,1,1,4,4,1,1,1,1,1,1,1,4,2,5,2,1,1,4,1,1,5,1,1,5,1,5,5,1,3,5,1,1,5,1,1,2,2,1,1,1,1,1,1,1,4,3,1,1,4,1,4,1,1,1,1,4,1,4,4,4,3,1,1,3,2,1,1,1,1,1,1,1,4,1,3,1,1,1,1,1,1,1,5,2,4,2,1,4,4,1,5,1,1,3,1,3,1,1,1,1,1,4,2,3,2,1,1,2,1,5,2,1,1,4,1,4,1,1,1,4,4,1,1,1,1,1,1,4,1,1,1,2,1,1,2]
class Fish:
def __init__(self, day, fesh):
self.fishcount = 0
self.days = day
self.fishcount += fesh
def dayend(self):
if self.days > 0:
self.days -= 1
return None
elif self.days == 0:
self.days = 6
return self.fishcount
def howmuchfish(self):
return self.fishcount
fishies = []
fishcounter = 0
for t in range(1, max(inp) + 1):
fishies.append(Fish(t, 0))
for i in inp:
for t in fishies:
if t.days == i:
t.fishcount += 1
for i in range(256):
newborn = 0
for t in fishies:
temp = t.dayend()
if temp is not None:
newborn += temp
fishies.append(Fish(8, newborn))
for t in fishies:
fishcounter += t.howmuchfish()
print(fishcounter)