您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1234567891011121314151617181920212223242526272829303132333435
  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()