Day 11, Part 1

This commit is contained in:
Jeremy Kescher 2023-12-19 19:23:19 +01:00
parent 74f8a66b21
commit 88ce597c46
Signed by: Jeremy Kescher
GPG key ID: 80A419A7A613DFA4
13 changed files with 76 additions and 0 deletions
Day06
Day07
Day08
Day09
Day10
Day11/Day11.Part1
aoc-2023.sln

View file

@ -5,6 +5,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
</PropertyGroup>
</Project>

View file

@ -5,6 +5,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
</PropertyGroup>
</Project>

View file

@ -5,6 +5,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
</PropertyGroup>
</Project>

View file

@ -5,6 +5,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
</PropertyGroup>
</Project>

View file

@ -5,6 +5,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
</PropertyGroup>
</Project>

View file

@ -5,6 +5,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
</PropertyGroup>
</Project>

View file

@ -5,6 +5,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
</PropertyGroup>
</Project>

View file

@ -5,6 +5,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
</PropertyGroup>
</Project>

View file

@ -5,6 +5,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
</PropertyGroup>
</Project>

View file

@ -5,6 +5,7 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,49 @@
List<ReadOnlyMemory<char>> lines = [];
while (Console.ReadLine().AsMemory() is { IsEmpty: false } line)
{
lines.Add(line);
// Vertical expansion
if (line.Span.IndexOf('#') == -1)
lines.Add(line);
}
var horizontalLength = lines.Count;
var verticalLength = lines[0].Length;
List<List<char>> expandedGrid = [];
for (var y = 0; y < verticalLength; y++)
{
var onlyDots = true;
for (var x = 0; x < horizontalLength; x++)
{
var cell = lines[x].Span[y];
if (y != 0) expandedGrid[x].Add(cell);
else expandedGrid.Add([cell]);
if (cell == '#') onlyDots = false;
}
if (onlyDots)
for (var x = 0; x < lines.Count; x++)
expandedGrid[x].Add('.');
}
List<(int X, int Y)> galaxyCoords = [];
horizontalLength = expandedGrid.Count;
verticalLength = expandedGrid[0].Count;
for (var x = 0; x < horizontalLength; x++)
for (var y = 0; y < verticalLength; y++)
if (expandedGrid[x][y] == '#')
galaxyCoords.Add((x, y));
var sum = 0;
// Calculate length of vectors between all coordinates
var galaxyCount = galaxyCoords.Count;
for (var first = 0; first < galaxyCount; first++)
for (var second = first + 1; second < galaxyCount; second++)
sum += Math.Abs(galaxyCoords[first].X - galaxyCoords[second].X) +
Math.Abs(galaxyCoords[first].Y - galaxyCoords[second].Y);
Console.WriteLine(sum);

View file

@ -40,6 +40,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Day10.Part1", "Day10\Day10.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Day10.Part2", "Day10\Day10.Part2\Day10.Part2.csproj", "{2590A865-0762-4C7E-A820-94DD77517AF8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Day11.Part1", "Day11\Day11.Part1\Day11.Part1.csproj", "{9B8BBF95-E459-418F-A534-3484BA1CD8FF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -126,5 +128,9 @@ Global
{2590A865-0762-4C7E-A820-94DD77517AF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2590A865-0762-4C7E-A820-94DD77517AF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2590A865-0762-4C7E-A820-94DD77517AF8}.Release|Any CPU.Build.0 = Release|Any CPU
{9B8BBF95-E459-418F-A534-3484BA1CD8FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B8BBF95-E459-418F-A534-3484BA1CD8FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B8BBF95-E459-418F-A534-3484BA1CD8FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B8BBF95-E459-418F-A534-3484BA1CD8FF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal