[2021] day 6 solved part 1 naively
This commit is contained in:
parent
51705d963f
commit
d9182cbff4
1
2021/.input/day06
Normal file
1
2021/.input/day06
Normal file
|
@ -0,0 +1 @@
|
|||
3,4,1,1,5,1,3,1,1,3,5,1,1,5,3,2,4,2,2,2,1,1,1,1,5,1,1,1,1,1,3,1,1,5,4,1,1,1,4,1,1,1,1,2,3,2,5,1,5,1,2,1,1,1,4,1,1,1,1,3,1,1,3,1,1,1,1,1,1,2,3,4,2,1,3,1,1,2,1,1,2,1,5,2,1,1,1,1,1,1,4,1,1,1,1,5,1,4,1,1,1,3,3,1,3,1,3,1,4,1,1,1,1,1,4,5,1,1,3,2,2,5,5,4,3,1,2,1,1,1,4,1,3,4,1,1,1,1,2,1,1,3,2,1,1,1,1,1,4,1,1,1,4,4,5,2,1,1,1,1,1,2,4,2,1,1,1,2,1,1,2,1,5,1,5,2,5,5,1,1,3,1,4,1,1,1,1,1,1,1,4,1,1,4,1,1,1,1,1,2,1,2,1,1,1,5,1,1,3,5,1,1,5,5,3,5,3,4,1,1,1,3,1,1,3,1,1,1,1,1,1,5,1,3,1,5,1,1,4,1,3,1,1,1,2,1,1,1,2,1,5,1,1,1,1,4,1,3,2,3,4,1,3,5,3,4,1,4,4,4,1,3,2,4,1,4,1,1,2,1,3,1,5,5,1,5,1,1,1,5,2,1,2,3,1,4,3,3,4,3
|
30
2021/Python/day06.py
Normal file
30
2021/Python/day06.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
class LanternFish:
|
||||
def __init__(self, cycle: int, current: int = None):
|
||||
self.cycle = cycle
|
||||
self.current = current or cycle
|
||||
self.children = []
|
||||
|
||||
def advance(self) -> None:
|
||||
self.current -= 1
|
||||
[child.advance() for child in self.children]
|
||||
if self.current == -1:
|
||||
self.current = self.cycle
|
||||
self.children.append(LanternFish(cycle=6, current=8))
|
||||
|
||||
def count(self) -> int:
|
||||
return 1 + sum([child.count() for child in self.children])
|
||||
|
||||
|
||||
def load() -> list[int]:
|
||||
with open('../.input/day06') as f:
|
||||
return [int(line) for line in f.read().split(",")]
|
||||
|
||||
|
||||
def solve1() -> int:
|
||||
fishes = [LanternFish(cycle=6, current=init) for init in load()]
|
||||
[[fish.advance() for fish in fishes] for _ in range(100)]
|
||||
return sum([fish.count() for fish in fishes])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(solve1())
|
Loading…
Reference in a new issue