Modeling the Expansion of Lanternfish Colonies
Компании, где спрашивали:
To simulate the process we use a numeric sequence that represents the breeding cycle of lanternfish and track the size of their population over a given number of days. Each lanternfish carries a counter that tells after how many days it will spawn a new fish. When the counter reaches zero, the fish resets it to 6 and creates a new individual whose counter starts at 8. The input consists of a list of integers, each corresponding to the counter of one lanternfish. For example, the initial state [3, 4, 3, 1, 2] denotes five lanternfish with the indicated counters.
The task is to run this simulation and report how many lanternfish exist after a specified number of days: 80 days for the basic version and 256 days for the advanced version.
Illustration of population growth:
- Initial state: 3,4,3,1,2
- After 1 day: 2,3,2,0,1
- After 2 days: 1,2,1,6,0,8
- After 3 days: 0,1,0,5,6,7,8