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.
Driving

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

  1. Your size starts at 1
  2. The shoal string will contain fish integers between 0-9
  3. 0 = algae and wont help you feed.
  4. The fish integer represents the size of the fish (1-9).
  5. You can only eat fish the same size or less than yourself.
  6. You can eat the fish in any order you choose to maximize your size.
  7. You can and only eat each fish once.
  8. 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.
  9. 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.

RankMaze Runner

RankScooby Doo Puzzle

RankDriving License

RankConnect 4

RankVending Machine

RankSnakes and Ladders

RankMastermind

RankGuess Who?

RankAm I safe to drive?

RankMexican Wave

RankPigs in a Pen

RankHungry Hippos

RankPlenty of Fish in the Pond

RankFruit Machine

RankCar Park Escape

Fundamentals

Stats:

CreatedApr 29, 2017
PublishedApr 29, 2017
Warriors Trained3968
Total Skips309
Total Code Submissions11947
Total Times Completed1522
Ruby Completions49
Python Completions528
JavaScript Completions398
C# Completions176
PHP Completions48
C++ Completions191
Haskell Completions32
C Completions62
TypeScript Completions73
VB Completions21
Rust Completions36
Total Stars148
% of votes with a positive feedback rating94% of 363
Total "Very Satisfied" Votes323
Total "Somewhat Satisfied" Votes35
Total "Not Satisfied" Votes5
Total Rank Assessments8
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • adrian.eyre Avatar
  • JohanWiltink Avatar
  • K1ngMX Avatar
  • rowcased Avatar
  • FArekkusu Avatar
  • WojciechBuczek Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • Just4FunCoder Avatar
  • WitherKNyx Avatar
  • KayleighWasTaken Avatar
Ad