Refactor Day03 corner generation to yield results
This commit is contained in:
1 parent
2113f8f2f1
commit
d637b1f0fa
1 file changed
+5
-8
+5
-8
@@ -86,20 +86,17 @@ public class Day03 : IPuzzleSolver<long>
|
||||
return points.All(p => p.x >= 0 && p.x < length && p.y >= 0 && p.y < width);
|
||||
}
|
||||
|
||||
private static List<(int x, int y)[]> GetAllPossibleCorners(char[][] forestGrid, int x, int y)
|
||||
private static IEnumerable<(int x, int y)[]> GetAllPossibleCorners(char[][] forestGrid, int x, int y)
|
||||
{
|
||||
var allCorners = new List<(int x, int y)[]>();
|
||||
var gridWidth = forestGrid[x].Length - 1;
|
||||
for (var squareWidth = gridWidth; squareWidth > 0; squareWidth--)
|
||||
var maxSquareWidth = forestGrid[x].Length - 1;
|
||||
for (var squareWidth = maxSquareWidth; squareWidth > 0; squareWidth--)
|
||||
{
|
||||
for (var skewAmount = 0; skewAmount < gridWidth; skewAmount++)
|
||||
for (var skewAmount = 0; skewAmount < maxSquareWidth; skewAmount++)
|
||||
{
|
||||
var corners = GetSkewedSquareCorners(x, y, skewAmount, squareWidth);
|
||||
allCorners.Add(corners);
|
||||
yield return corners;
|
||||
}
|
||||
}
|
||||
|
||||
return allCorners;
|
||||
}
|
||||
|
||||
private static (int x, int y)[] GetSkewedSquareCorners(int x, int y, int skewAmount, int squareWidth)
|
||||
|
||||
Reference in new issue
Block a user