class LanternfishSchool: def __init__(self, counts, size_inc=100000): self.time_left = {} self.time_left["ttr"] = 0 for i in range(9): self.time_left[i] = counts.count(i) self.size_inc = size_inc self.size_base = size_inc def age(self): self.time_left["ttr"] = self.time_left[0] for i in range(1,9): self.time_left[i-1] = self.time_left[i] self.time_left[8] = self.time_left["ttr"] self.time_left[6] += self.time_left["ttr"] self.time_left["ttr"] = 0 if self.school_size() >= self.size_base: print(f"School size now {self.school_size()}.") def school_size(self): total = 0 for _,v in self.time_left.items(): total += v return total def main(): # The old version gets untenable above about 100 days. # Trying a different approach. num_days = 256 with open("aoc6-1.txt", "r") as file: fish_ages = [int(age) for age in file.readlines()[0].split(",")] lfs = LanternfishSchool(fish_ages) for _ in range(num_days): lfs.age() print(lfs.school_size()) if __name__ == "__main__": main()