Today's challenge is [here](https://adventofcode.com/2021/day/6). We have to find the amount of fish 'split' after some days. A problem based on [exponential growth](https://en.wikipedia.org/wiki/Exponential_growth).
When I started doing this challenge I first thought about using Object-Oriented Programming, but that didn't work out. When calculating large amounts of fish I started to run out of memory and the algorithm was too slow.
Loading the data:
```python
def load() -> list[int]:
with open('../.input/day06') as f:
return [int(line) for line in f.read().split(",")]
```
## Task 1
Pretty simple, we just need to advance the fish and then count the amount of fish. I created simple methods in the `LanternFish` class that do just that.
Here's a class that represents a fish:
```python
class LanternFish:
def __init__(self, cycle: int, current: int = None):
return 1 + sum([child.count() for child in self.children])
```
Here we iterate through number of days and advance the fish. The way fishes are related to each other is that they all form a tree. When I advance a fish, I also advance all of its children. The amount of fish is the sum of the amount of fish in the tree.
```python
def solve1() -> int:
fishes = [LanternFish(cycle=6, current=init) for init in load()]
[[fish.advance() for fish in fishes] for _ in range(80)]
return sum([fish.count() for fish in fishes])
```
## Task 2
Here I took a different approach, I stored the fishes in a simple dictionary. The key is the day and the value is the number of fishes. I then iterate through the days and advance the fishes.
The way this works is kind of hard to explain really, but the key to it all is the `%` [modulo operator](https://en.wikipedia.org/wiki/Modulo_operation). The modulo operator returns the remainder of a division. In this case, the modulo operator is used to determine whether some fish should give birth.