6 kyu
Plenty of Fish in the Pond
398 of 1,522adrian.eyre
Description:
Introduction
Fish are an integral part of any ecosystem. Unfortunately, fish are often seen as high maintenance. Contrary to popular belief, fish actually reduce pond maintenance as they graze on string algae and bottom feed from the pond floor. They also make very enjoyable pets, providing hours of natural entertainment.

Task
In this Kata 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 function that takes a shoal of fish as an input string. From this you must work out how many fish you can eat and ultimately the size you will grow to and return this as an integer.
Rules
- Your size starts at
1
- The shoal string 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 and 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.
Increase your size
Your size will increase depending how many fish you eat and on the size of the fish.
This chart shows the amount of size 1
fish you have to eat in order to increase your size.
Current size | Amount extra needed for next size | Total size 1 fish | Increase to 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 |
Example 1
"11112222" => 3
=> 4 fish of size 1
=> 4 fish of size 2
- You eat the 4 fish of size 1 (4 * 1 = 4) which increases your size to 2
- Now that you are size 2 you can eat the fish that are sized 1 or 2.
- You then eat the 4 fish of size 2 (4 * 2 = 8) which increases your size to 3
Example 2
shoal = "111111111111" => 3
=> 12 fish of size 1
- You eat the 4 fish of size 1 (4 * 1 = 4) which increases your size to 2
- You then eat the remainding 8 fish of size 1 (8 * 1 = 8) which increases your size to 3
Good luck and enjoy!
Kata Series
If you enjoyed this, then please try one of my other Katas. Any feedback, translations and grading of beta Katas are greatly appreciated. Thank you.
Fundamentals
Similar Kata:
Stats:
Created | Apr 29, 2017 |
Published | Apr 29, 2017 |
Warriors Trained | 3968 |
Total Skips | 309 |
Total Code Submissions | 11947 |
Total Times Completed | 1522 |
Ruby Completions | 49 |
Python Completions | 528 |
JavaScript Completions | 398 |
C# Completions | 176 |
PHP Completions | 48 |
C++ Completions | 191 |
Haskell Completions | 32 |
C Completions | 62 |
TypeScript Completions | 73 |
VB Completions | 21 |
Rust Completions | 36 |
Total Stars | 148 |
% of votes with a positive feedback rating | 94% of 363 |
Total "Very Satisfied" Votes | 323 |
Total "Somewhat Satisfied" Votes | 35 |
Total "Not Satisfied" Votes | 5 |
Total Rank Assessments | 8 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |