Skip to content

Commit db6872b

Browse files
10-2023 Part 2
1 parent 51ed866 commit db6872b

File tree

4 files changed

+113
-27
lines changed

4 files changed

+113
-27
lines changed

2023/Day10/Solution.cs

Lines changed: 89 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ public object PartOne(string input)
1515
// We find where the 'S' is
1616
var startingPoint = FindStartingPoint(lines);
1717
pipesMap.Add(startingPoint.Key, startingPoint.Value);
18-
18+
1919
while (true)
2020
{
2121
var currentPoint = new ValueTuple<int, int>();
2222
var newDirection = Direction.Down;
23-
23+
2424
if (pipesMap.Last().Value == Direction.Right)
2525
{
2626
currentPoint = (pipesMap.Last().Key.Item1, pipesMap.Last().Key.Item2 + 1);
@@ -41,22 +41,104 @@ public object PartOne(string input)
4141
currentPoint = (pipesMap.Last().Key.Item1 + 1, pipesMap.Last().Key.Item2);
4242
newDirection = GetNewDirection(Direction.Down, lines[currentPoint.Item1][currentPoint.Item2]);
4343
}
44-
44+
4545
if (newDirection == Direction.End)
4646
{
4747
// We went back to the previous point
4848
break;
4949
}
50-
50+
5151
pipesMap.Add(currentPoint, newDirection);
5252
}
53-
53+
5454
return (pipesMap.Count) / 2;
5555
}
5656

5757
public object PartTwo(string input)
5858
{
59-
return 0;
59+
var lines = ParseLines(input);
60+
var pipesMap = new Dictionary<(int, int), Direction>();
61+
var visitedTiles = new HashSet<(int, int)>();
62+
// We find where the 'S' is
63+
var startingPoint = FindStartingPoint(lines);
64+
65+
pipesMap.Add(startingPoint.Key, startingPoint.Value);
66+
visitedTiles.Add(startingPoint.Key);
67+
68+
while (true)
69+
{
70+
var currentPoint = new ValueTuple<int, int>();
71+
var newDirection = Direction.Down;
72+
73+
if (pipesMap.Last().Value == Direction.Right)
74+
{
75+
currentPoint = (pipesMap.Last().Key.Item1, pipesMap.Last().Key.Item2 + 1);
76+
newDirection = GetNewDirection(Direction.Right, lines[currentPoint.Item1][currentPoint.Item2]);
77+
}
78+
else if (pipesMap.Last().Value == Direction.Left)
79+
{
80+
currentPoint = (pipesMap.Last().Key.Item1, pipesMap.Last().Key.Item2 - 1);
81+
newDirection = GetNewDirection(Direction.Left, lines[currentPoint.Item1][currentPoint.Item2]);
82+
}
83+
else if (pipesMap.Last().Value == Direction.Up)
84+
{
85+
currentPoint = (pipesMap.Last().Key.Item1 - 1, pipesMap.Last().Key.Item2);
86+
newDirection = GetNewDirection(Direction.Up, lines[currentPoint.Item1][currentPoint.Item2]);
87+
}
88+
else if (pipesMap.Last().Value == Direction.Down)
89+
{
90+
currentPoint = (pipesMap.Last().Key.Item1 + 1, pipesMap.Last().Key.Item2);
91+
newDirection = GetNewDirection(Direction.Down, lines[currentPoint.Item1][currentPoint.Item2]);
92+
}
93+
94+
if (newDirection == Direction.End)
95+
{
96+
// We went back to the previous point
97+
break;
98+
}
99+
100+
pipesMap.Add(currentPoint, newDirection);
101+
visitedTiles.Add(currentPoint);
102+
}
103+
104+
// We modify Starting point for algo
105+
var index = startingPoint.Key.Item2;
106+
var str = lines[startingPoint.Key.Item1];
107+
var newStr = str.Remove(index, 1).Insert(index, "L");
108+
lines[startingPoint.Key.Item1] = newStr;
109+
110+
var insideCount = 0;
111+
for (int y = 1; y < lines.Length - 1; y++)
112+
{
113+
for (int x = 1; x < lines[0].Length - 1; x++)
114+
{
115+
if (visitedTiles.Contains((y, x)))
116+
{
117+
continue;
118+
}
119+
120+
var crossings = 0;
121+
122+
for (int i = x + 1; i < lines[0].Length; i++)
123+
{
124+
var tile = lines[y][i];
125+
// If we find a wall
126+
var symbols = new[] { '|', 'J', 'L' };
127+
128+
if (visitedTiles.Contains((y, i)) && symbols.Contains(tile))
129+
{
130+
crossings++;
131+
}
132+
}
133+
134+
if (crossings % 2 == 1)
135+
{
136+
insideCount++;
137+
}
138+
}
139+
}
140+
141+
return insideCount;
60142
}
61143

62144
private static string[] ParseLines(string input) =>
@@ -127,4 +209,4 @@ internal enum Direction
127209
Left,
128210
Right,
129211
End
130-
}
212+
}

2023/Day10/input.refout

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
6875
1+
6875
2+
471

2023/SplashScreen.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,26 @@ public void Show() {
99

1010
var color = Console.ForegroundColor;
1111
Write(0xcc00, false, " ▄█▄ ▄▄█ ▄ ▄ ▄▄▄ ▄▄ ▄█▄ ▄▄▄ ▄█ ▄▄ ▄▄▄ ▄▄█ ▄▄▄\n █▄█ █ █ █ █ █▄█ █ █ █ █ █ █▄ ");
12-
Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ 0x0000 | 2023\n ");
13-
Write(0xcc00, false, " \n \n ");
14-
Write(0xcc00, false, " \n \n ");
15-
Write(0xcc00, false, " \n ");
16-
Write(0xcc00, false, " \n ");
17-
Write(0x333333, false, " * ");
18-
Write(0x666666, false, "12\n ");
19-
Write(0x333333, false, "' ' \n ");
12+
Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ /^2023$/\n \n ");
13+
Write(0xcc00, false, " \n ");
14+
Write(0xcc00, false, " \n \n ");
15+
Write(0x333333, false, " * ");
16+
Write(0x666666, false, "13\n \n * ");
17+
Write(0x666666, false, " ");
18+
Write(0xcccccc, false, "12 ");
19+
Write(0x666666, false, "**\n ");
20+
Write(0xd4dde4, false, "' ' \n ");
2021
Write(0x666666, false, " * ");
2122
Write(0xcccccc, false, "11 ");
22-
Write(0x666666, false, "**\n '. * ..'");
23+
Write(0x666666, false, "**\n ");
24+
Write(0xd4dde4, false, "'. ");
25+
Write(0xffff66, true, "* ");
26+
Write(0xd4dde4, false, "..'");
2327
Write(0xe3b585, false, "' ''... ");
2428
Write(0xcccccc, false, "10 ");
25-
Write(0xffff66, false, "*");
26-
Write(0x666666, false, "*\n ");
29+
Write(0xffff66, false, "**\n ");
2730
Write(0xe3b585, false, ".");
28-
Write(0x333333, false, "'''");
31+
Write(0xd4dde4, false, "'''");
2932
Write(0xe3b585, false, "~ ~ ~ ~ ");
3033
Write(0x6b4d3b, false, "### ");
3134
Write(0xe3b585, false, "''. \n .' ~ ");

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy