Day 6
This commit is contained in:
parent
1b510bf789
commit
14d274e5d8
2
Day5.cs
2
Day5.cs
|
|
@ -1,4 +1,4 @@
|
||||||
#define Day5
|
// #define Day5
|
||||||
#define PartTwo
|
#define PartTwo
|
||||||
#if Day5
|
#if Day5
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
#define Day6
|
||||||
|
#if Day6
|
||||||
|
var fish = File.ReadAllText("day6/input").Split(",")
|
||||||
|
.Select(long.Parse)
|
||||||
|
.GroupBy(x => x)
|
||||||
|
.ToDictionary(x => x.Key, x => x.LongCount());
|
||||||
|
|
||||||
|
fish[0] = 0;
|
||||||
|
fish[6] = 0;
|
||||||
|
fish[7] = 0;
|
||||||
|
fish[8] = 0;
|
||||||
|
|
||||||
|
Console.WriteLine(CalculateGrowth(80, Copy(fish)));
|
||||||
|
Console.WriteLine(CalculateGrowth(256, Copy(fish)));
|
||||||
|
|
||||||
|
long CalculateGrowth(int numberOfDays, Dictionary<long, long> fishState) {
|
||||||
|
while (numberOfDays > 0) {
|
||||||
|
long newFish = fishState[0];
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
fishState[i] = fishState[i + 1];
|
||||||
|
}
|
||||||
|
fishState[6] += newFish;
|
||||||
|
fishState[8] = newFish;
|
||||||
|
|
||||||
|
numberOfDays--;
|
||||||
|
}
|
||||||
|
return fishState.Values.Sum();
|
||||||
|
}
|
||||||
|
|
||||||
|
Dictionary<long, long> Copy(Dictionary<long, long> dict) {
|
||||||
|
return dict.ToDictionary(entry => entry.Key,
|
||||||
|
entry => entry.Value);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
5,4,3,5,1,1,2,1,2,1,3,2,3,4,5,1,2,4,3,2,5,1,4,2,1,1,2,5,4,4,4,1,5,4,5,2,1,2,5,5,4,1,3,1,4,2,4,2,5,1,3,5,3,2,3,1,1,4,5,2,4,3,1,5,5,1,3,1,3,2,2,4,1,3,4,3,3,4,1,3,4,3,4,5,2,1,1,1,4,5,5,1,1,3,2,4,1,2,2,2,4,1,2,5,5,1,4,5,2,4,2,1,5,4,1,3,4,1,2,3,1,5,1,3,4,5,4,1,4,3,3,3,5,5,1,1,5,1,5,5,1,5,2,1,5,1,2,3,5,5,1,3,3,1,5,3,4,3,4,3,2,5,2,1,2,5,1,1,1,1,5,1,1,4,3,3,5,1,1,1,4,4,1,3,3,5,5,4,3,2,1,2,2,3,4,1,5,4,3,1,1,5,1,4,2,3,2,2,3,4,1,3,4,1,4,3,4,3,1,3,3,1,1,4,1,1,1,4,5,3,1,1,2,5,2,5,1,5,3,3,1,3,5,5,1,5,4,3,1,5,1,1,5,5,1,1,2,5,5,5,1,1,3,2,2,3,4,5,5,2,5,4,2,1,5,1,4,4,5,4,4,1,2,1,1,2,3,5,5,1,3,1,4,2,3,3,1,4,1,1
|
||||||
Loading…
Reference in New Issue