Suppose the lanternfish live forever and have unlimited food and space. Would they take over the entire ocean?
After 256 days in the example above, there would be a total of 26984457539
lanternfish!
How many lanternfish would there be after 256 days? Determine this in the following way:
lanternfish
that takes the pathname (string
) of a text file containing the ages of several hundred nearby lanternfish. The function must return how many lanternfish (number
) there would be after 256 days.In this interactive session we assume the text files ages01.txt
1 and ages02.txt
2 to be located in the current directory.
> lanternfish("ages01.txt")
26984457539
> lanternfish("ages02.txt")
1650309278600
Jari Komppa (@Sol_HSA3) animated his solution.