1
0
Fork 0
advent-of-code/2021/day6.cs

26 lines
507 B
C#
Raw Normal View History

2024-02-08 09:55:40 +01:00
string input;
using (var sr = new System.IO.StreamReader("../inputs/day6.txt"))
input = sr.ReadToEnd();
var startPop = input.Split(",").Select(int.Parse).ToList();
var pop = new long[9];
foreach (var fish in startPop)
pop[fish] += 1;
for (int i = 0; i < 256; i++)
{
long newFishes = pop[0];
for (int j = 0; j < 8; j++)
pop[j] = pop[j + 1];
pop[8] = newFishes;
pop[6] += newFishes;
if (i == 79)
Console.WriteLine(pop.Sum());
}
Console.WriteLine(pop.Sum());