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.

aoc6-1.py 941B

3 years ago
123456789101112131415161718192021222324252627282930313233343536
  1. class Lanternfish:
  2. def __init__(self, count=None):
  3. self.count = 8 if count == None else count
  4. def age(self):
  5. self.count -= 1
  6. if self.count == -1:
  7. self.count = 6
  8. return True
  9. return False
  10. def main():
  11. num_days = 80
  12. with open("aoc6-1.txt", "r") as file:
  13. fish_ages = [int(age) for age in file.readlines()[0].split(",")]
  14. fishes = []
  15. for age in fish_ages:
  16. fishes.append(Lanternfish(age))
  17. fish_benchmark, fish_increment = 10000, 10000
  18. for day in range(num_days):
  19. num_fish = len(fishes)
  20. if num_fish > fish_benchmark:
  21. print(f"Reached {num_fish} lanternfish on day {day}.")
  22. fish_benchmark += fish_increment
  23. for i in range(num_fish):
  24. if fishes[i].age():
  25. fishes.append(Lanternfish())
  26. print(len(fishes))
  27. return len(fishes)
  28. if __name__ == "__main__":
  29. main()