-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
37 lines (28 loc) · 852 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using AdventOfCode.Common;
var population = Resources.GetInputFileLines().First().SplitToNumbers();
static long[] CreateHistogram(IEnumerable<int> population)
{
var histogram = new long[9];
foreach (var i in population)
{
histogram[i]++;
}
return histogram;
}
static long Evolve(IEnumerable<int> population, int generations)
{
long[] histogram = CreateHistogram(population);
for (int i = 0; i < generations; i++)
{
var readyToBreed = histogram[0];
for (int j = 0; j < histogram.Length - 1; j++)
{
histogram[j] = histogram[j + 1];
}
histogram[8] = readyToBreed;
histogram[6] += readyToBreed;
}
return histogram.Sum();
}
Console.WriteLine($"Part 1: {Evolve(population, 80)}");
Console.WriteLine($"Part 2: {Evolve(population, 256)}");