Skip to content

Commit

Permalink
Day 14 (Part 1)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Dec 21, 2023
1 parent 4bb17e0 commit 982c87b
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 0 deletions.
12 changes: 12 additions & 0 deletions AdventOfCode.sln
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Day15_1", "Day15_1\Day15_1.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Day15_2", "Day15_2\Day15_2.csproj", "{FC6C72A1-79AB-4B32-A0E8-53318D0ADEBF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Day14_1", "Day14_1\Day14_1.csproj", "{A5BF10EE-D307-4B48-9FAA-974B58AEEA69}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Day14_2", "Day14_2\Day14_2.csproj", "{16D82E13-BC73-42F6-B459-D93D76265A5A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -183,6 +187,14 @@ Global
{FC6C72A1-79AB-4B32-A0E8-53318D0ADEBF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC6C72A1-79AB-4B32-A0E8-53318D0ADEBF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC6C72A1-79AB-4B32-A0E8-53318D0ADEBF}.Release|Any CPU.Build.0 = Release|Any CPU
{A5BF10EE-D307-4B48-9FAA-974B58AEEA69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A5BF10EE-D307-4B48-9FAA-974B58AEEA69}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5BF10EE-D307-4B48-9FAA-974B58AEEA69}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5BF10EE-D307-4B48-9FAA-974B58AEEA69}.Release|Any CPU.Build.0 = Release|Any CPU
{16D82E13-BC73-42F6-B459-D93D76265A5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{16D82E13-BC73-42F6-B459-D93D76265A5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{16D82E13-BC73-42F6-B459-D93D76265A5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{16D82E13-BC73-42F6-B459-D93D76265A5A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
24 changes: 24 additions & 0 deletions Day14_1/Day14_1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<None Remove="input.txt" />
</ItemGroup>

<ItemGroup>
<Content Include="input.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

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

</Project>
79 changes: 79 additions & 0 deletions Day14_1/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
var input = File.ReadAllLines("input.txt");

var width = input[0].Length;
var height = input.Length;

var map = new char[width, height];

for (var y = 0; y < height; y++)
{
for (var x = 0; x < width; x++)
{
map[x, y] = input[y][x];
}
}

TiltUp(map, width, height);

for (var y = 0; y < height; y++)
{
for (var x = 0; x < width; x++)
{
Console.Write(map[x, y]);
}
Console.WriteLine();
}

Console.WriteLine(CalculateLoad(map, width, height));

static void TiltUp(char[,] map, int width, int height)
{
for (int x = 0; x < width; x++)
{
void OutputStones(int stones, int y)
{
for (int i = 0; i < stones; i++)
{
map[x, y + 1 + i] = 'O';
}
}

// Start at the bottom of the column
var stones = 0;
var y = height - 1;
while (y >= 0)
{
if (map[x, y] == 'O')
{
// Go up, count stones and replace with empty
stones++;
map[x, y] = '.';
}
else if (map[x, y] == '#')
{
OutputStones(stones, y);
stones = 0;
}
y--;
}

OutputStones(stones, y);
}
}

static int CalculateLoad(char[,] map, int width, int height)
{
var load = 0;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
if (map[x, y] == 'O')
{
load += (height - y);
}
}
}

return load;
}
7 changes: 7 additions & 0 deletions Day14_1/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"profiles": {
"Run": {
"commandName": "Project"
}
}
}
10 changes: 10 additions & 0 deletions Day14_1/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
O....#....
O.OO#....#
.....##...
OO.#O....O
.O.....O#.
O.#..O.#.#
..O..#O..O
.......O..
#....###..
#OO..#....
Empty file added Day14_1/output.txt
Empty file.

0 comments on commit 982c87b

Please sign in to comment.