Skip to content

Commit

Permalink
Day 14
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkAD88 committed Dec 16, 2023
1 parent 56c1771 commit 2f4af5b
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
C# implementations and tests using .NET 8 for the [Advent of Code 2023](https://adventofcode.com/2023/) event.

```text
--------Part 1--------- --------Part 2---------
Day Time Rank Score Time Rank Score
14 >24h 32685 0 - - -
13 >24h 31355 0 >24h 29258 0
11 03:12:35 13331 0 16:34:32 33500 0
10 04:02:42 12311 0 - - -
Expand Down Expand Up @@ -46,4 +48,7 @@ Part one tripped me up. I don't have a clue how to accomplish Part 2.
Had an epiphany this morning and refactored the code to improve the solve speed. Sleeping on issues really is my magic power.

## Day 13
Finally got around to this while travelling. Hard problem to solve if for no other reason than I misread the instructions regarding how to calculate the values. Part two was a beast. I got 90% of the way there but kept coming up with the wrong answer still. The issue was introduced by my approach to the problem. I was accidentally ignoring valid results if the horizontal non-smudged index was the same as the smudged vertical index. So much trial and error and manual string checking to troubleshoot.
Finally got around to this while travelling. Hard problem to solve if for no other reason than I misread the instructions regarding how to calculate the values. Part two was a beast. I got 90% of the way there but kept coming up with the wrong answer still. The issue was introduced by my approach to the problem. I was accidentally ignoring valid results if the horizontal non-smudged index was the same as the smudged vertical index. So much trial and error and manual string checking to troubleshoot.

## Day 14
Part one of this was super easy - solved it in about 15 minutes. Too bad I started it nearly a day late. However, I just read the intructions for part 2 and I'm not sure how I'm goint to solve for it. Might be a nasty one.
30 changes: 30 additions & 0 deletions code/Day14.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace code
{
public static class Day14
{
public static long TaskOne(string[] lines)
{
long result = 0;

for (var x = 0; x < lines[0].Length; x++)
{
var rockValue = lines.Length;
for (var y = 0; y < lines.Length; y++)
{
if (lines[y][x] == 'O')
{
result += rockValue;
rockValue -= 1;
}

if (lines[y][x] == '#')
{
rockValue = lines.Length - (y + 1);
}
}
}

return result;
}
}
}
7 changes: 6 additions & 1 deletion code/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@
lines = File.ReadAllLines(Path.Combine("inputs", "day11-full.txt"));
Console.WriteLine($"Day11-a: {Day11.TaskOne(lines)}");
Console.WriteLine($"Day11-b: {Day11.TaskTwo(lines)}");
*/
// Day 13
lines = File.ReadAllLines(Path.Combine("inputs", "day13-full.txt"));
Console.WriteLine($"Day13-a: {Day13.TaskOne(lines)}");
Console.WriteLine($"Day13-b: {Day13.TaskTwo(lines)}");
*/

// Day 13
lines = File.ReadAllLines(Path.Combine("inputs", "day14-full.txt"));
Console.WriteLine($"Day14-a: {Day14.TaskOne(lines)}");
Console.WriteLine($"Day14-b: {Day14.TaskOne(lines)}");
3 changes: 3 additions & 0 deletions code/code.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
<None Update="inputs\day13-sample.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="inputs\day14-full.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>


</ItemGroup>
Expand Down
100 changes: 100 additions & 0 deletions code/inputs/day14-full.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
O..##O.#..#..#...##O#.#...OO....O.#.....O......#OO...#...OO....O....O....O#.O.....O.#.O..O.O#......#
.O.#..O...#....#...O..OO..#..O.O.....O.O...#O....#O.#O...OO#.O.#O##.......#.#OO#.O.O...O....O.....O#
O.O.O......#..#.O.#O........##.#...#...#....O........#O#...#.O...O.O..O.OO#.#..#.#....O..O.#.#..O.O.
......##O.......#O.OO.OO#..#O....#OO...O......O.OO#O#...#....#.O.#.O#..O..O.O...OOO..O........#...O#
#...###.O.#O#OOO#O...OO..O.O.##.#.........O.........OO.OOO#...O.#O....#.......O.OO#.#...O..#....O..O
.O....#...#.#.OO.O#..O.....O...OO..##..O.....#..O.OO..#.O..O..##...O..OO...O#...O.....##.O..O.O.O.##
...#.#O..OO.#..#.#.##...O.OO.O#.O##OO.O..#...#O.....OO..O.###.#...#.#O....##...#O...#..O.#...##.....
...O...O..O...#O#.##....#..O#..O..............O.....O..#........##...O.##..#.O.O.O......OO#O.#..#OOO
.#O......O..#..O..#.......#...#O....O..O#.........O.O....O....OO....O#....OOO.OO..O.#.O#........#.OO
#.O.O.O.........O.#...O...#.O#.O.O#O#...................##.OO..#.O.......#...O##O.O.......O...O.OOOO
....#.#.O...OO.O..#.O..O...#.OO.#O...O.O.O..........O..#...OO..##.O.OOO...O#....O..O....O..OO.O..O..
OO.#...#...O#..O##..OO#O.O.O.#OO..O....O#O..#O#.##OO........OO..O##.#.#.....##...O........O..O.O.O..
.O...O..O##...O....O.....O..#...#.#..##O#.O...O.O....#........O......#O#O#.#O#......O..O#..O....O...
O.O#....O#.OO##OO.#.O..#.O#.....#...#O#.#O.....OO#.......OOO.#..O..#OO.#...#.O.#O.O.O#.O.O..O..#.#..
##....#...###.......O...O........O.....O.OOOO.#.##...........O.O#O..#.#.#...#....#O.O#.#OO..##.....#
.#..#...#.....O.O.##..O#O#..##..#.#O.....O..#O##..#......O..#..#.#.O..#O..#.......O#...O#.OO..O.O...
#.....O....#......##.O......O..##....#.O...........O.O#.O##O...#.##..O.#.........#......#.O....OO...
.#.OO..O...#...O..###.O#.O.O..........#...#O..###O##..#.O.OO..#O.O..OO#.##.##...O...OOO....O.....O.#
.O..#...O.#...O.#............#...#.##....#.O.O#.....O....O..#..OO#O..#.#.OO........O..O..#O..#...O#.
.O..O..#O..O.OOOO...O....#...#.#.#.OO..OO.#....O#.......#..OO####O..O#O...O..O##...O#...#.........#.
..##O...##...##...O..##...#.....O##.....#..O...O..........O.OOOO...#O#.O###.O.#O......OO...O..#OO#..
O..#.O........#..OO...#O..OO...#.....OOOO........OO.......#O.O..#OO...O..#......O.#.OO..O....O....#.
.O#.O.#.O..#.OO...........#..#O.#...O.......#...........#.##..O#O...O..#...O.O...#........O..O.OO.#.
#OO.........#...O....O.O......#.O#.....OO.#O.OO..O..O............OO.....O....O.O...O.O....O.....OO..
...#O...#...#O#..OO.O..#........#O..O.O.O......O....#...O.O..O....#O...O...#.##.O...#...#.OO.....O..
..#.O#.O#..###..O#.O.O..O.#......O..OO.O..O.....O..##.#........O#.O.##O.#....#.O#.#.O#O..OO...#..#OO
OOOO.#..#....OO...O.##O#.#O...O..#O.O.OO....#O#.#O.O...#....O......#....O.......#.O.O.OOO...#OO..O.O
#...O#OO##O.OO.....O.O......O..O....O.O..O......#OO..O....#....OOOO#.....O#OOO#....O.O....OO...#O..#
.#O..#.###...O...#.O.#.....O.O.....#OOOO.#..O.#O.#....##..#.#..O#.#.....O....O.O#O...O...OO.###.....
........OO###.#..............O..O.OOO.#O.O...O.OO...#O.O.....#O#OOO.#O#..O#.#...O..#..##.#..O.......
........O#.#.O...OO.O...##..#..O....#......OO...#...O.......#O.#....#O#...O...O...OO...OO.#.O#...OOO
O....O.............#.OO#O..O#..O#.##.#..O..O.##....##O...##.OO......#OOO...#OO..OO#......O.O..O.O...
.......OO.#..O.O##...#..OOO.#.O..........................###.OO#O.O#.#..........O....O...##....OO..O
.#..O..O.OOO#OO.#O...#...O...O#OO.O......#..O.##....O.....#...O...O#..#...###O......####.....O##....
.O#O..##...O..#OO.....#...........#.#O.#..O..OO.O....OO.#.O..#....##.O#....O.#..#.#.....#.#O.O.O...#
...O##..O#.#.O..#........O.##......O.O.O#O.#O..O...O..OO...O...O.O.O#O...O.O..OO..OOO..#.O#OO....O..
.#...O.....O#..O.#...O.O....##O....#...#O...O..#......O#....#OO.O.#..#.....##.O.#OO..O#.......O..O#O
......#O.#.....###.O...O.............OO.......O..#......O....#.O.#.....O#O..#....#O......O.O..#.....
#O###..O.O#.O#.#.O..#.......#.##.O.O......O......###...#.OO.OO.##.O#O.#.......##.O...O#O.O..##..#.#.
...OO...##O#O.#..O..O...O.O..#....###.....#......#.O....#..O.#.....O##.O....OOO.#..#O###.O.O.O..#.O.
#.#.....#.OO...O...O#...O...#..#..#.O.OO.#OO#...OO#.....#.....O....O.O....O...O.#...O...OOOO...O..O.
OO..OOO.#O.O.O...#.###O..OOO..#....O.....#...##....#..#....O.O#...O....#.....O.O.#O...O.....OOO....#
...##.O.#O#O....O......O#.#..........#.#.O...O...##..O.##.......O...O.###....O...#..O..O..O.....O..O
.O......#OOO.....#OO...OO.O.##...#......#O.....O.....O..##O......#OO.O......O#......#O##.#OO..O..O..
...#O..#...O#..O........O..O.....OOO.#.O.O..##.....O##..###..#..O#O....O......#..O.#.O.O.#.....OO#O.
O...#.O##.O..#.#O.......#....#..##.#O#.OO......O.#...OOO##.#.O..O.O..#..#O......#..O.....OO.......##
....OO....#O.O#O#.....O.O....O...#.#OO...O......#O.O#..#.O....#.....O...O..........#.O....##O.O#.#O#
......#.O....OOO#.O...#..O...OO#..#..............O#..O.#.........O...#.O.......O............O..#O#..
#.#........O.O....O#..OO..#...O.#O#..O.OO....#O...###.OO.......#..O...##.#..##.....O##.O..........#.
#O..#...O.....O.O.O...#O.#..O....O..#.#..O.O.#O...O##O##.OO...O....OO##.....##.#.O.#..OOO..O.#O..#O.
........#.O..O..#......O.#.O..#OOOOO..#O...#.....O.#..O.....O.#.O.OO.O.#.....O..........OO.......O.#
...O..##.O...#....O.O....#..#.#...OO...#...O.#.O.....#...O..O.....#....##.#O..#.#....##...OO....O.#.
.....#..##O...#O..O#O.#..##.O.O.O..#.O##.O#........O....#.O##O..#O##O#...O..##O#.#.OO...O##.#....O..
O.OO..O#...OO......O...O.O........##....OO.O..#...O........#.....##.O....#.O.O.O#.......O.O#O....O..
#.O....#.....O.OO#...#..O.....#..OO...OO#....O....#........O......#...#..#O#O....#.#........O..##.O#
#..OO..O......#O.O#.O...#.#....O.O#.O..#.OOO#.O##.....#.OO...O.O..#..##..O.#O#....O.#....OO..#......
#..OO..#..#.#O.OOO##.O..O#.#O..O..O.....O...O...#...#..........#...O..#O...#..OO...#..O.#OOO...#....
......#.O....#..OO.OO...#...O...........#O.OO...#.#..O.O...##....#..#........#......#.O..#..O##O....
#.##..#O##....O..........O.O.##..#O..O..#.OO.O.O.#....#.....OOOO..##.#OO.#.O.#O......#.#.#.O..OO..#.
#O..#..O..O....O#.OO...#.O.#..O.##.O.....OO.O....O.....O.#.O....O....O....##O...O..O.OO.......O#..O.
.O.....#.#.........OO..........#.O.#.O#.....#.....O...O.#O.............O#.#..O..O........#.##O..#...
O.....#....O...#OOO##..####.#.....O.....#...#...#...##..........#..####............O...OOO.O.#...#..
.#O#OOO..#..O..#.O#.O#.O.O##.....O#..##O....#..O#......O#...O#.O.....O.O#..OO........O..O..#.#.....O
.O#...#...#O#.....##.#O.#...#......O..O.O.........OOOO..#.#....OO.#.O.O..#.O...O.#.#...OO..#.OOO..#O
#..#..#..#.#.#.......O#...O.#O..O..#.......#..O.#.....#.#.O.O##..#..##O.#......O...O...#O.OOO#.O.##.
.O......OO..OO.O..##.#.#..O....O...O..##...........O..................O.#...O...O..O.#.O..OOOO..#..O
.OOOOO...O......##.#..O..O.##.OO#.#.##.##O..#........#....O..#..O#..O.OOO....O#..O......O.O..#...#.#
OO..#.#O...#.O.O.O.#.O.#...O...O.##..##..#.#..O....O.......#...#.#OO##.O.OOO...O#.....O.##......OO..
...O..O.....###O....OO#....#OO....O##.###.#O..#..OO..O.O#.O......##.O#.O#O....O..#.OO#O.#..O...OO...
..##..#..OOOOO#O..#O.##..OO.#.O.......O...O##.#.O...O...O..O..O..#.O......#....#O..#.#.#.......O....
....O.............O....O..##.OOO.#.#....#O..O..........#..#O..##.O##O.O...........O....#.....OO..OO.
....O...#..O.....OO..#...O.OO#..O.##.O..O.##.#.O..#.#O......#.OO....#....##..#...O#......#O......O..
.....#O#...#..O..OOO#O....O..O..O.OO.........##.O..#O#......O..O.O.O.OO#.#.O.O..O..O..O....#...#O...
..O#O##...#.O...........#O..##.O.O.#..O...O#O.#.O.........O.O...#.#O....OO#O#.O#..O..#.#O.O.OO#O....
........OO..#...O.....O................#..O..........#.#.O.....#..OO.....O...O..O....#..#..........#
#..OO.O......O.#..OO.O##...OO.....O#.O.....O#....##.##.O.OOO.O...O..#.O....#OO...OO..#.#.......O....
..O...#O.....O.OO.#..#.#O.O##O.O...#.O#...O.#O...#O....#..O..O..O.....#OO.O..O..##.O....##.....#OO..
..O..O.#....#.#OO.......O.OO..O.........O....#...O#.#..O.O...O.O..###OO..O#..#.....O.O.....#.#O..O.O
.#O..O#.....#...OOO..#OO#.O.......O..O......OO...O.#.O##O...##...#.....O...O....O.O.##...#..........
O.##..#...#.O...#.##..O...#..O.#O.O##.##.O..O.O..O.OO..O....#.#O..O.O.O....#.#..O#..#O..#....O......
OO##OO...O.#.OOO...#O..#O......O..O#.O.......#....OO.O.#...O.O.......O#O........##.#.O....#....O..#.
.O.....O#..#...#.....#.O..O.#.#O......##....OO....O...#.#.#........O.........OO....O#...##OO...O.O.#
O#.##...O.#OO...##.OO#.....O.O.OO#...#....O.O..O.O.#.OO.O...O#...O#.#OO..O#.#.#O....O....O#.#O.OOO#.
##..#.O#.OOO#.......O.#O.O#......O.####OO......O..O..OO.....#.O..O#.OO..O.#O.#.O.O..##OO....#.......
.#......O..#..#...OO......O...O....O...O..........O.O..O..O..###...OOO..O..O..O.O........O.O........
#OO.O..O.OO......#.##.......O..O#.OOO..#..O.#........##.#.O....O.#O#..O...#............O...O....#...
.#...#O..#.....O...O#.O...#O..........##.#OO..##..O#..O.#.O...O#..O..O.OO.O.####O....##.O......###O.
.O.#OO#O..................#..#...O.#.O.#..OO.O.O.............###..O..OO##.O..........O#..O......##.#
.O.O..O.....OOO..#O.O.###.O.....OO#O....#...#....O......#.........#...##.O##O...##....O#OO#.O...#.O.
##..#OO#O..#..OO#.O#OOOO.O.##O...OO..O.O.O.OO##O.O.O.O.O...OO...O.##....O...##O#.OO#.#...O......#O.#
.#..#.#.O......OOOO....O#....#...O#O..OOO.#O#OO......##....O##..#.O.O...........O.O....##...O.......
#....O.........O#O.O.....O.###.###.O......#..OO..#.O...O##..O.O..OO..#.O....#...#.##O.O.OO...#O.OO..
...O..OOO......O.#O.#.##.......#.#...#...OOO....#........O....OO.OO.O..O##..O#O.......##.O....O.....
...#.O#.#.O#.OO...#..##........#..O##..#O.#.......##O....O..O...O...#..#O...O.......#..O#.#..#O.#...
O....O...OO.O...OO.O..O...O..##O..O...O...O#.#....O.........#.O#.O.#..#.O.O.O.O....O#.O..##OO..OO...
.#..#.OO...OO..OO...OO..#.OO.....#.##..##.O...O.#..#..#....#.O.O.......OO##..##..O.O...O..OOO.......
O...O..#.....O#O..##..O..#OO....#.#O#.O.OO.O.O.OO#....##.#.O....O..#O#.#....#O..#O.##.O..OO...#.....
..#....O#.#.##...##..O....##.#O.......O#O..#....#.#.........OO..####O...O##..O#OO...O......#O..#..#.
...#.....O.O.O.#.#..#..#O.O..O...O.#.O..#...#....O......#.OO...O....O.O.#.#...O....##....##.OO......
..##O....O.#.#..#......OO#O.O..#.O.O..#O.OO...#....O..O#O........#OOOO....#O...#....#O##..#O#....#..
34 changes: 34 additions & 0 deletions tests.unit/Day14Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using code;

using FluentAssertions;
namespace tests.unit
{
public class Day14Tests
{
[Fact]
public void TaskOneSample()
{
string[] input = [
"O....#....",
"O.OO#....#",
".....##...",
"OO.#O....O",
".O.....O#.",
"O.#..O.#.#",
"..O..#O..O",
".......O..",
"#....###..",
"#OO..#....",
];

Day14.TaskOne(input).Should().Be(136);
}

[Fact]
public void TaskOne()
{
var input = File.ReadAllLines(Path.Combine("inputs", "day14-full.txt"));
Day14.TaskOne(input).Should().Be(110090);
}
}
}

0 comments on commit 2f4af5b

Please sign in to comment.