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-2.py 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. class LanternfishSchool:
  2. def __init__(self, counts, size_inc=100000):
  3. self.time_left = {}
  4. self.time_left["ttr"] = 0
  5. for i in range(9):
  6. self.time_left[i] = counts.count(i)
  7. self.size_inc = size_inc
  8. self.size_base = size_inc
  9. def age(self):
  10. self.time_left["ttr"] = self.time_left[0]
  11. for i in range(1,9):
  12. self.time_left[i-1] = self.time_left[i]
  13. self.time_left[8] = self.time_left["ttr"]
  14. self.time_left[6] += self.time_left["ttr"]
  15. self.time_left["ttr"] = 0
  16. if self.school_size() >= self.size_base:
  17. print(f"School size now {self.school_size()}.")
  18. self.size_base += self.size_inc
  19. def school_size(self):
  20. total = 0
  21. for _,v in self.time_left.items():
  22. total += v
  23. return total
  24. def main():
  25. # The 6-1 version gets untenable above about 100 days.
  26. # Trying a different approach.
  27. num_days = 256
  28. with open("aoc6-1.txt", "r") as file:
  29. fish_ages = [int(age) for age in file.readlines()[0].split(",")]
  30. lfs = LanternfishSchool(fish_ages)
  31. for _ in range(num_days):
  32. lfs.age()
  33. print(lfs.school_size())
  34. if __name__ == "__main__":
  35. main()