# 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 called fish 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.


# 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


 



Please note: The chart represents fish of size 1

# Returns

Return an integer of the maximum size you could be.


# Example 1
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



```python
fish("11112222") => 3
```

# Example 2

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

```python
fish("111111111111") => 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.

 Maze Runner
 Scooby Doo Puzzle
 Driving License
 Connect 4
 Vending Machine
 Snakes and Ladders
 Mastermind
 Guess Who?
 Am I safe to drive?
 Mexican Wave
 Pigs in a Pen
 Hungry Hippos
 Plenty of Fish in the Pond
 Fruit Machine
 Car Park Escape

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def fish(shoal):
	

Solutions:
def fish(shoal):
	(eaten, size, target) = (0, 1, 4)
	for f in sorted(map(int, shoal)):
		if f > size:
			break
		eaten += f
		if eaten >= target:
			size += 1
			target += 4 * size
	return size


from collections import Counter

def fish(shoal):
	(size, eaten) = (1, 0)
	for (fishesSize, n) in sorted(Counter(map(int, shoal)).items()):
		eaten += fishesSize * n if fishesSize <= size else 0
		size = 1 + int(((1 + 2 * eaten) ** 0.5 - 1) / 2)
	return size


def fish(shoal, size=1, protein_earned=0):
	fishes = [int(fish) for fish in shoal if fish != '0']
	grow = True
	while grow:
		edible_fishes = list(filter(lambda x: x <= size, fishes))
		ate_protein = sum(edible_fishes)
		protein_earned += ate_protein
		if protein_earned >= protein_to_grow(size):
			size += 1
			fishes = [fish for fish in fishes if fish not in edible_fishes]
		else:
			grow = False
	return size

def protein_to_grow(actual_size):
	protein_to_accumulate = 0
	while actual_size > 0:
		protein_to_accumulate += actual_size * 4
		actual_size -= 1
	return protein_to_accumulate


def fish(shoal):
	size = 1
	while count_lesser_fish(shoal, size) >= 2 * size * (size + 1):
		size += 1
	return size

def count_lesser_fish(shoal, size):
	return sum((int(f) for f in shoal if int(f) <= size))


def fish(shoal):
	fishes = sorted(shoal)
	my_size = 1
	amount_for_next_size = 4
	for i in range(len(fishes)):
		if int(fishes[i]) > my_size:
			break
		amount_for_next_size -= int(fishes[i])
		if amount_for_next_size <= 0:
			my_size += 1
			amount_for_next_size += my_size * 4
	return my_size


def fish(shoal):
	(size, eaten) = (1, 0)
	for i in range(1, 10):
		if size < i:
			break
		eaten += i * shoal.count(str(i))
		size = max(size, int(((2 * eaten + 1) ** 0.5 - 1) / 2) + 1)
	return size


class Fish:
	size = 1
	intake = 0

def attemptDigestion(myFish, menuItem):
	if menuItem <= myFish.size:
		myFish.intake += menuItem

def assessGrowth(myFish):
	if myFish.intake >= 4 * myFish.size:
		myFish.intake = myFish.intake - 4 * myFish.size
		myFish.size += 1

def fish(str):
	foodPool = []
	foodPool[:0] = str
	foodPool.sort()
	myFish = Fish()
	while foodPool and int(foodPool[0]) <= myFish.size:
		menuItem = int(foodPool.pop(0))
		attemptDigestion(myFish, menuItem)
		assessGrowth(myFish)
	return myFish.size


from collections import Counter

def fish(shoal):
	count = Counter(map(int, shoal))
	(size, eaten, step) = (1, 0, 4)
	for n in range(1, 10):
		if size >= n:
			eaten += count[n] * n
			while eaten >= step:
				eaten -= step
				size += 1
				step += 4
		else:
			break
	return size


from collections import Counter

def fish(shoal):
	c = Counter(map(int, shoal.replace('0', '')))
	consumed = 0
	for size in range(1, 99999):
		consumed += size * c[size]
		if consumed < size * (size + 1) * 2:
			return size


def fish(shoal):
	shoal_l = []
	for s in shoal:
		shoal_l.append(int(s))
		shoal_l.sort()
	max_size = 1
	food_count = 0
	amount_needed = 4
	for fishy in shoal_l:
		if max_size >= fishy:
			food_count += int(fishy)
		if food_count >= amount_needed:
			max_size += 1
			amount_needed += max_size * 4
	return max_size