Skip to content

Commit

Permalink
10-2023 Part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent-seguin committed Dec 12, 2023
1 parent 51ed866 commit db6872b
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 27 deletions.
96 changes: 89 additions & 7 deletions 2023/Day10/Solution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public object PartOne(string input)
// We find where the 'S' is
var startingPoint = FindStartingPoint(lines);
pipesMap.Add(startingPoint.Key, startingPoint.Value);

while (true)
{
var currentPoint = new ValueTuple<int, int>();
var newDirection = Direction.Down;

if (pipesMap.Last().Value == Direction.Right)
{
currentPoint = (pipesMap.Last().Key.Item1, pipesMap.Last().Key.Item2 + 1);
Expand All @@ -41,22 +41,104 @@ public object PartOne(string input)
currentPoint = (pipesMap.Last().Key.Item1 + 1, pipesMap.Last().Key.Item2);
newDirection = GetNewDirection(Direction.Down, lines[currentPoint.Item1][currentPoint.Item2]);
}

if (newDirection == Direction.End)
{
// We went back to the previous point
break;
}

pipesMap.Add(currentPoint, newDirection);
}

return (pipesMap.Count) / 2;
}

public object PartTwo(string input)
{
return 0;
var lines = ParseLines(input);
var pipesMap = new Dictionary<(int, int), Direction>();
var visitedTiles = new HashSet<(int, int)>();
// We find where the 'S' is
var startingPoint = FindStartingPoint(lines);

pipesMap.Add(startingPoint.Key, startingPoint.Value);
visitedTiles.Add(startingPoint.Key);

while (true)
{
var currentPoint = new ValueTuple<int, int>();
var newDirection = Direction.Down;

if (pipesMap.Last().Value == Direction.Right)
{
currentPoint = (pipesMap.Last().Key.Item1, pipesMap.Last().Key.Item2 + 1);
newDirection = GetNewDirection(Direction.Right, lines[currentPoint.Item1][currentPoint.Item2]);
}
else if (pipesMap.Last().Value == Direction.Left)
{
currentPoint = (pipesMap.Last().Key.Item1, pipesMap.Last().Key.Item2 - 1);
newDirection = GetNewDirection(Direction.Left, lines[currentPoint.Item1][currentPoint.Item2]);
}
else if (pipesMap.Last().Value == Direction.Up)
{
currentPoint = (pipesMap.Last().Key.Item1 - 1, pipesMap.Last().Key.Item2);
newDirection = GetNewDirection(Direction.Up, lines[currentPoint.Item1][currentPoint.Item2]);
}
else if (pipesMap.Last().Value == Direction.Down)
{
currentPoint = (pipesMap.Last().Key.Item1 + 1, pipesMap.Last().Key.Item2);
newDirection = GetNewDirection(Direction.Down, lines[currentPoint.Item1][currentPoint.Item2]);
}

if (newDirection == Direction.End)
{
// We went back to the previous point
break;
}

pipesMap.Add(currentPoint, newDirection);
visitedTiles.Add(currentPoint);
}

// We modify Starting point for algo
var index = startingPoint.Key.Item2;
var str = lines[startingPoint.Key.Item1];
var newStr = str.Remove(index, 1).Insert(index, "L");
lines[startingPoint.Key.Item1] = newStr;

var insideCount = 0;
for (int y = 1; y < lines.Length - 1; y++)
{
for (int x = 1; x < lines[0].Length - 1; x++)
{
if (visitedTiles.Contains((y, x)))
{
continue;
}

var crossings = 0;

for (int i = x + 1; i < lines[0].Length; i++)
{
var tile = lines[y][i];
// If we find a wall
var symbols = new[] { '|', 'J', 'L' };

if (visitedTiles.Contains((y, i)) && symbols.Contains(tile))
{
crossings++;
}
}

if (crossings % 2 == 1)
{
insideCount++;
}
}
}

return insideCount;
}

private static string[] ParseLines(string input) =>
Expand Down Expand Up @@ -127,4 +209,4 @@ internal enum Direction
Left,
Right,
End
}
}
3 changes: 2 additions & 1 deletion 2023/Day10/input.refout
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
6875
6875
471
27 changes: 15 additions & 12 deletions 2023/SplashScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,26 @@ public void Show() {

var color = Console.ForegroundColor;
Write(0xcc00, false, " ▄█▄ ▄▄█ ▄ ▄ ▄▄▄ ▄▄ ▄█▄ ▄▄▄ ▄█ ▄▄ ▄▄▄ ▄▄█ ▄▄▄\n █▄█ █ █ █ █ █▄█ █ █ █ █ █ █▄ ");
Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ 0x0000 | 2023\n ");
Write(0xcc00, false, " \n \n ");
Write(0xcc00, false, " \n \n ");
Write(0xcc00, false, " \n ");
Write(0xcc00, false, " \n ");
Write(0x333333, false, " * ");
Write(0x666666, false, "12\n ");
Write(0x333333, false, "' ' \n ");
Write(0xcc00, false, " █ █ █ █ █ █▄█\n █ █ █▄█ ▀▄▀ █▄▄ █ █ █▄ █▄█ █ █▄ █▄█ █▄█ █▄▄ /^2023$/\n \n ");
Write(0xcc00, false, " \n ");
Write(0xcc00, false, " \n \n ");
Write(0x333333, false, " * ");
Write(0x666666, false, "13\n \n * ");
Write(0x666666, false, " ");
Write(0xcccccc, false, "12 ");
Write(0x666666, false, "**\n ");
Write(0xd4dde4, false, "' ' \n ");
Write(0x666666, false, " * ");
Write(0xcccccc, false, "11 ");
Write(0x666666, false, "**\n '. * ..'");
Write(0x666666, false, "**\n ");
Write(0xd4dde4, false, "'. ");
Write(0xffff66, true, "* ");
Write(0xd4dde4, false, "..'");
Write(0xe3b585, false, "' ''... ");
Write(0xcccccc, false, "10 ");
Write(0xffff66, false, "*");
Write(0x666666, false, "*\n ");
Write(0xffff66, false, "**\n ");
Write(0xe3b585, false, ".");
Write(0x333333, false, "'''");
Write(0xd4dde4, false, "'''");
Write(0xe3b585, false, "~ ~ ~ ~ ");
Write(0x6b4d3b, false, "### ");
Write(0xe3b585, false, "''. \n .' ~ ");
Expand Down
Loading

0 comments on commit db6872b

Please sign in to comment.