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:
Write a function 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 (int
) there would be after 256 days.
The function must be declared statically in the class Submission.
In this interactive session we assume the text files ages01.txt
1 and ages02.txt
2 to be located in the current directory.
> Submission.lanternfish("ages01.txt")
26984457539
> Submission.lanternfish("ages02.txt")
1650309278600
Jari Komppa (@Sol_HSA3) animated his solution.