-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay6.cs
50 lines (43 loc) · 1.32 KB
/
Day6.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
38
39
40
41
42
43
44
45
46
47
48
49
50
namespace AdventOfCode
{
public static class Day6
{
public static int Part1()
{
List<int> fish = DataService.GetDay6Data();
for (int day = 1; day <= 80; day++)
{
for (int i = 0; i < fish.Count; i++)
{
switch (fish[i] - 1)
{
case -1:
fish[i] = 6;
fish.Add(9);
break;
default:
fish[i]--;
break;
}
}
}
return fish.Count;
}
public static ulong Part2()
{
List<int> fish = DataService.GetDay6Data();
ulong[] fishPerState = new ulong[9];
foreach (int f in fish)
fishPerState[Convert.ToUInt64(f)]++;
for (int day = 1; day <= 256; day++)
{
ulong fishStateZero = fishPerState[0];
for (int i = 0; i < 8; i++)
fishPerState[i] = fishPerState[i + 1];
fishPerState[6] += fishStateZero;
fishPerState[8] = fishStateZero;
}
return fishPerState.Sum(f => f);
}
}
}