## The challenge

### Part 1

The sea floor is getting steeper. Maybe the sleigh keys got carried this way?

A massive school of glowing lanternfish swims past. They must spawn quickly to reach such large numbers - maybe exponentially quickly? You should model their growth rate to be sure.

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.

However, this process isn’t necessarily synchronized between every lanternfish - one lanternfish might have 2 days left until it creates another lanternfish, while another might have 4. So, you can model each fish as a single number that represents the number of days until it creates a new lanternfish.

Furthermore, you reason, a new lanternfish would surely need slightly longer before it’s capable of producing more lanternfish: two more days for its first cycle.

So, suppose you have a lanternfish with an internal timer value of 3:

• After one day, its internal timer would become 2.
• After another day, its internal timer would become 1.
• After another day, its internal timer would become 0.
• After another day, its internal timer would reset to 6, and it would create a new lanternfish with an internal timer of 8.
• After another day, the first lanternfish would have an internal timer of 5, and the second lanternfish would have an internal timer of 7.

A lanternfish that creates a new fish resets its timer to 6, not 7 (because 0 is included as a valid timer value). The new lanternfish starts with an internal timer of 8 and does not start counting down until the next day.

Realizing what you’re trying to do, the submarine automatically produces a list of the ages of several hundred nearby lanternfish (your puzzle input).

[…]

Find a way to simulate lanternfish. How many lanternfish would there be after 80 days?

You can read the challenge more in depth, here.

### Part 2

Suppose the lanternfish live forever and have unlimited food and space. Would they take over the entire ocean?

[…]

How many lanternfish would there be after 256 days?

## Full solution

``````auto input = stdin.byLineCopy().front.splitter(",").map!(to!ubyte).array; // input
auto count = iota(0,9).map!(s => input.count!(a => a == s)).array;        // count fish lifes
iota(0,256).each!((d){count[(d+7)%9]+=count[d%9];});                      // calculate number of fishes per day
count.sum.writeln;                                                        // sum all fishes
``````