1234567891011121314151617181920212223242526272829303132333435 |
- class Lanternfish:
- def __init__(self, count=None):
- self.count = 8 if count == None else count
-
- def age(self):
- self.count -= 1
- if self.count == -1:
- self.count = 6
- return True
- return False
-
- def main():
- num_days = 80
-
- with open("aoc6-1.txt", "r") as file:
- fish_ages = [int(age) for age in file.readlines()[0].split(",")]
- fishes = []
- for age in fish_ages:
- fishes.append(Lanternfish(age))
-
- fish_benchmark, fish_increment = 10000, 10000
- for day in range(num_days):
- num_fish = len(fishes)
- if num_fish > fish_benchmark:
- print(f"Reached {num_fish} lanternfish on day {day}.")
- fish_benchmark += fish_increment
- for i in range(num_fish):
- if fishes[i].age():
- fishes.append(Lanternfish())
-
- print(len(fishes))
- return len(fishes)
-
- if __name__ == "__main__":
- main()
|