Day 11, Part 1
This commit is contained in:
parent
74f8a66b21
commit
88ce597c46
13 changed files with 76 additions and 0 deletions
|
@ -5,6 +5,7 @@
|
|||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
|
|
11
Day11/Day11.Part1/Day11.Part1.csproj
Normal file
11
Day11/Day11.Part1/Day11.Part1.csproj
Normal 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>
|
49
Day11/Day11.Part1/Program.cs
Normal file
49
Day11/Day11.Part1/Program.cs
Normal 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);
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue