Skip to content

Commit

Permalink
day 6
Browse files Browse the repository at this point in the history
  • Loading branch information
bsssshhhhhhh committed Dec 6, 2021
1 parent fb06553 commit c1708a1
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 0 deletions.
44 changes: 44 additions & 0 deletions day 06/part1/Program.cs
@@ -0,0 +1,44 @@
using AdventCommon;
var lines = ConsoleHelpers.ReadInput();
var lanternfish = lines[0]
.Split(",")
.Select(int.Parse)
.Aggregate(new Dictionary<int, long>() {
{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {6, 0}, {7, 0}, {8, 0}
} , (acc, cur) => {
if (!acc.TryGetValue(cur, out _))
{
acc[cur] = 1;
}
else
{
acc[cur]++;
}
return acc;
});

var simulateDay = () => {
foreach (var kvp in lanternfish.ToDictionary(k => k.Key, v => v.Value))
{
if (kvp.Key == 0)
{
lanternfish[kvp.Key] = 0;
lanternfish[6] += kvp.Value;
lanternfish[8] += kvp.Value;
}
else
{
lanternfish[kvp.Key] -= kvp.Value;
lanternfish[kvp.Key - 1] += kvp.Value;
}
}
};


for (var i = 0; i < 80; i++)
{
simulateDay();
}

Console.WriteLine(lanternfish.Values.Sum());
1 change: 1 addition & 0 deletions day 06/part1/input.txt
@@ -0,0 +1 @@
1,1,3,5,1,3,2,1,5,3,1,4,4,4,1,1,1,3,1,4,3,1,2,2,2,4,1,1,5,5,4,3,1,1,1,1,1,1,3,4,1,2,2,5,1,3,5,1,3,2,5,2,2,4,1,1,1,4,3,3,3,1,1,1,1,3,1,3,3,4,4,1,1,5,4,2,2,5,4,5,2,5,1,4,2,1,5,5,5,4,3,1,1,4,1,1,3,1,3,4,1,1,2,4,2,1,1,2,3,1,1,1,4,1,3,5,5,5,5,1,2,2,1,3,1,2,5,1,4,4,5,5,4,1,1,3,3,1,5,1,1,4,1,3,3,2,4,2,4,1,5,5,1,2,5,1,5,4,3,1,1,1,5,4,1,1,4,1,2,3,1,3,5,1,1,1,2,4,5,5,5,4,1,4,1,4,1,1,1,1,1,5,2,1,1,1,1,2,3,1,4,5,5,2,4,1,5,1,3,1,4,1,1,1,4,2,3,2,3,1,5,2,1,1,4,2,1,1,5,1,4,1,1,5,5,4,3,5,1,4,3,4,4,5,1,1,1,2,1,1,2,1,1,3,2,4,5,3,5,1,2,2,2,5,1,2,5,3,5,1,1,4,5,2,1,4,1,5,2,1,1,2,5,4,1,3,5,3,1,1,3,1,4,4,2,2,4,3,1,1
14 changes: 14 additions & 0 deletions day 06/part1/part1.csproj
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\..\common\common.csproj" />
</ItemGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
44 changes: 44 additions & 0 deletions day 06/part2/Program.cs
@@ -0,0 +1,44 @@
using AdventCommon;
var lines = ConsoleHelpers.ReadInput();
var lanternfish = lines[0]
.Split(",")
.Select(int.Parse)
.Aggregate(new Dictionary<int, long>() {
{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {6, 0}, {7, 0}, {8, 0}
} , (acc, cur) => {
if (!acc.TryGetValue(cur, out _))
{
acc[cur] = 1;
}
else
{
acc[cur]++;
}
return acc;
});

var simulateDay = () => {
foreach (var kvp in lanternfish.ToDictionary(k => k.Key, v => v.Value))
{
if (kvp.Key == 0)
{
lanternfish[kvp.Key] = 0;
lanternfish[6] += kvp.Value;
lanternfish[8] += kvp.Value;
}
else
{
lanternfish[kvp.Key] -= kvp.Value;
lanternfish[kvp.Key - 1] += kvp.Value;
}
}
};


for (var i = 0; i < 256; i++)
{
simulateDay();
}

Console.WriteLine(lanternfish.Values.Sum());
1 change: 1 addition & 0 deletions day 06/part2/input.txt
@@ -0,0 +1 @@
1,1,3,5,1,3,2,1,5,3,1,4,4,4,1,1,1,3,1,4,3,1,2,2,2,4,1,1,5,5,4,3,1,1,1,1,1,1,3,4,1,2,2,5,1,3,5,1,3,2,5,2,2,4,1,1,1,4,3,3,3,1,1,1,1,3,1,3,3,4,4,1,1,5,4,2,2,5,4,5,2,5,1,4,2,1,5,5,5,4,3,1,1,4,1,1,3,1,3,4,1,1,2,4,2,1,1,2,3,1,1,1,4,1,3,5,5,5,5,1,2,2,1,3,1,2,5,1,4,4,5,5,4,1,1,3,3,1,5,1,1,4,1,3,3,2,4,2,4,1,5,5,1,2,5,1,5,4,3,1,1,1,5,4,1,1,4,1,2,3,1,3,5,1,1,1,2,4,5,5,5,4,1,4,1,4,1,1,1,1,1,5,2,1,1,1,1,2,3,1,4,5,5,2,4,1,5,1,3,1,4,1,1,1,4,2,3,2,3,1,5,2,1,1,4,2,1,1,5,1,4,1,1,5,5,4,3,5,1,4,3,4,4,5,1,1,1,2,1,1,2,1,1,3,2,4,5,3,5,1,2,2,2,5,1,2,5,3,5,1,1,4,5,2,1,4,1,5,2,1,1,2,5,4,1,3,5,3,1,1,3,1,4,4,2,2,4,3,1,1
14 changes: 14 additions & 0 deletions day 06/part2/part2.csproj
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\..\common\common.csproj" />
</ItemGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>

0 comments on commit c1708a1

Please sign in to comment.