You are fish in a pond that needs to survive by eating other fish. You can only eat fish that are the same size or smaller than yourself. You must create a program that takes a shoal of fish as sorted input. From this you must work out how many fish you can eat and ultimately the size you will grow to.
Size chart
+--------------+--------------+--------------+--------------+
| | Amount extra | Total size 1 | Increase to |
| Current size | needed for | fish | size |
| | next size | | |
+--------------+--------------+--------------+--------------+
| 1 | 4 | 4 | 2 |
+--------------+--------------+--------------+--------------+
| 2 | 8 | 12 | 3 |
+--------------+--------------+--------------+--------------+
| 3 | 12 | 24 | 4 |
+--------------+--------------+--------------+--------------+
| 4 | 16 | 40 | 5 |
+--------------+--------------+--------------+--------------+
| 5 | 20 | 60 | 6 |
+--------------+--------------+--------------+--------------+
| 6 | 24 | 84 | 7 |
+--------------+--------------+--------------+--------------+
Rules
- Your size starts at 1
- The shoal input will contain fish integers between 0-9
- 0 = algae and wont help you feed.
- The fish integer represents the size of the fish (1-9).
- You can only eat fish the same size or less than yourself.
- You can eat the fish in any order you choose to maximize your size.
- You can only eat each fish once.
- The bigger fish you eat, the faster you grow. A size 2 fish equals two size 1 fish, size 3 fish equals three size 1 fish, and so on.
- Your size increments by one each time you reach the amounts below.
Returns an integer of the maximum size you could be
Examples
"11112222" => 3
4 fish size 1 increases to 2, 4 size 2 makes you 3
"111111111111" => 3
4 fish size 1 increases to 2, 8 size 1 makes you 3
The shortest code (counting in bytes) to do so in any language in which numbers wins.
5,6
or6,6
from Mark's last example and get to size 13; yet remove5,5
instead and one can only reach size five. \$\endgroup\$