Advent of Code 2021 - Day 6

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.

export const d6 = ({
  input = inputs.d6,
  part,
}: {
  input?: string
  part: 'a' | 'b'
}) => {
  let state = reduce(
    ints(input),
    (state, i) => (state[i]++, state),
    Array(9).fill(0),
  )
  const days = part === 'a' ? 80 : 256
  for (let day = 0; day < days; day++) {
    state[9] = state[0]
    state[7] += state[0]
    state.shift()
  }
  return sum(state)
}

Day 6a sample:

Day 6a mine:

Day 6b sample:

Day 6b mine: