generated from MartinZikmund/template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4bb17e0
commit 982c87b
Showing
6 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"profiles": { | ||
"Run": { | ||
"commandName": "Project" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.