Although you know nothing about this specific species of lanternfish, you make some guesses about their attributes. Surely, each lanternfish creates a new lanternfish once every 7 days.

Ah, rationality.

Times for today: Embarrassing. I stalled out in the middle and went and did other stuff for a bit. I got about half of the way to the fundamental insight; that each fish is not unique. This problem is something like sequences or exponential modeling. I eventually gave up and looked at a few solutions on the reddit, then wrote one of my own. Can’t win ‘em all.

Code


def model_lanterfish_clever(start, niter=80):
    fish = [start.count(i) for i in range(9)]

    for i in range(niter):
        n = fish.pop(0)
        fish.append(n)
        fish[6] += n

    return sum(fish)