|
| 1 | +# --- Day 6: Lanternfish --- |
| 2 | + |
| 3 | +## --- Part One --- |
| 4 | + |
| 5 | +The sea floor is getting steeper. Maybe the sleigh keys got carried this way? |
| 6 | + |
| 7 | +A massive school of glowing lanternfish swims past. They must spawn quickly to reach such large numbers - |
| 8 | +maybe exponentially quickly? You should model their growth rate to be sure. |
| 9 | + |
| 10 | +Although you know nothing about this specific species of lanternfish, you make some guesses about their attributes. |
| 11 | +Surely, each lanternfish creates a new lanternfish once every 7 days. |
| 12 | + |
| 13 | +However, this process isn't necessarily synchronized between every lanternfish - one lanternfish might have 2 days |
| 14 | +left until it creates another lanternfish, while another might have 4. So, you can model each fish as a single number |
| 15 | +that represents the number of days until it creates a new lanternfish. |
| 16 | + |
| 17 | +Furthermore, you reason, a new lanternfish would surely need slightly longer before it's capable of producing more |
| 18 | +lanternfish: two more days for its first cycle. |
| 19 | + |
| 20 | +So, suppose you have a lanternfish with an internal timer value of 3: |
| 21 | + |
| 22 | +- After one day, its internal timer would become 2. |
| 23 | +- After another day, its internal timer would become 1. |
| 24 | +- After another day, its internal timer would become 0. |
| 25 | +- After another day, its internal timer would reset to 6, and it would create a new lanternfish with an |
| 26 | +internal timer of 8. |
| 27 | +- After another day, the first lanternfish would have an internal timer of 5, and the second lanternfish would have |
| 28 | +an internal timer of 7. |
| 29 | + |
| 30 | +A lanternfish that creates a new fish resets its timer to 6, not 7 (because 0 is included as a valid timer value). |
| 31 | +The new lanternfish starts with an internal timer of 8 and does not start counting down until the next day. |
| 32 | + |
| 33 | +Realizing what you're trying to do, the submarine automatically produces a list of the ages of several hundred nearby |
| 34 | +lanternfish (your puzzle input). For example, suppose you were given the following list: |
| 35 | + |
| 36 | +```text |
| 37 | +3,4,3,1,2 |
| 38 | +``` |
| 39 | + |
| 40 | +This list means that the first fish has an internal timer of 3, the second fish has an internal timer of 4, |
| 41 | +and so on until the fifth fish, which has an internal timer of 2. Simulating these fish over several days would |
| 42 | +proceed as follows: |
| 43 | + |
| 44 | +```text |
| 45 | +Initial state: 3,4,3,1,2 |
| 46 | +After 1 day: 2,3,2,0,1 |
| 47 | +After 2 days: 1,2,1,6,0,8 |
| 48 | +After 3 days: 0,1,0,5,6,7,8 |
| 49 | +After 4 days: 6,0,6,4,5,6,7,8,8 |
| 50 | +After 5 days: 5,6,5,3,4,5,6,7,7,8 |
| 51 | +After 6 days: 4,5,4,2,3,4,5,6,6,7 |
| 52 | +After 7 days: 3,4,3,1,2,3,4,5,5,6 |
| 53 | +After 8 days: 2,3,2,0,1,2,3,4,4,5 |
| 54 | +After 9 days: 1,2,1,6,0,1,2,3,3,4,8 |
| 55 | +After 10 days: 0,1,0,5,6,0,1,2,2,3,7,8 |
| 56 | +After 11 days: 6,0,6,4,5,6,0,1,1,2,6,7,8,8,8 |
| 57 | +After 12 days: 5,6,5,3,4,5,6,0,0,1,5,6,7,7,7,8,8 |
| 58 | +After 13 days: 4,5,4,2,3,4,5,6,6,0,4,5,6,6,6,7,7,8,8 |
| 59 | +After 14 days: 3,4,3,1,2,3,4,5,5,6,3,4,5,5,5,6,6,7,7,8 |
| 60 | +After 15 days: 2,3,2,0,1,2,3,4,4,5,2,3,4,4,4,5,5,6,6,7 |
| 61 | +After 16 days: 1,2,1,6,0,1,2,3,3,4,1,2,3,3,3,4,4,5,5,6,8 |
| 62 | +After 17 days: 0,1,0,5,6,0,1,2,2,3,0,1,2,2,2,3,3,4,4,5,7,8 |
| 63 | +After 18 days: 6,0,6,4,5,6,0,1,1,2,6,0,1,1,1,2,2,3,3,4,6,7,8,8,8,8 |
| 64 | +``` |
| 65 | + |
| 66 | +Each day, a 0 becomes a 6 and adds a new 8 to the end of the list, while each other number decreases by 1 if it was |
| 67 | +present at the start of the day. |
| 68 | + |
| 69 | +In this example, after 18 days, there are a total of 26 fish. After 80 days, there would be a total of 5934. |
| 70 | + |
| 71 | +Find a way to simulate lanternfish. How many lanternfish would there be after 80 days? |
| 72 | + |
| 73 | +## --- Part Two --- |
| 74 | +Suppose the lanternfish live forever and have unlimited food and space. Would they take over the entire ocean? |
| 75 | + |
| 76 | +After 256 days in the example above, there would be a total of 26984457539 lanternfish! |
| 77 | + |
| 78 | +How many lanternfish would there be after 256 days? |
0 commit comments