Refactor Day04 and Day09 to rename methods and variables for improved clarity and update Day09 tests with additional input file and test case
This commit is contained in:
parent
411672d8c3
commit
82772fd4e0
|
|
@ -7,6 +7,7 @@ public class Day09Test
|
|||
private IPuzzleSolver<long> _sut;
|
||||
private static readonly string rootPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
||||
private readonly string TestInputPath = @$"{rootPath}\AoC-PuzzleInputs\2025\Test\day09.txt";
|
||||
private readonly string Test2InputPath = @$"{rootPath}\AoC-PuzzleInputs\2025\Test\day09_2.txt";
|
||||
private readonly string ProdInputPath = @$"{rootPath}\AoC-PuzzleInputs\2025\Prod\day09.txt";
|
||||
|
||||
public Day09Test()
|
||||
|
|
@ -37,6 +38,15 @@ public class Day09Test
|
|||
Assert.Equal(24, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Part02_Test2_equals_30()
|
||||
{
|
||||
// todo: color edges as right, left, up, down to only allow rectangles between right and left or up and down edges
|
||||
var actual = _sut.SolvePart2(Test2InputPath);
|
||||
|
||||
Assert.Equal(30, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Part02_Prod_equals_1568849600()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -55,13 +55,12 @@ public class Day04 : IPuzzleSolver<long>
|
|||
private HashSet<Coordinate> GetRollCoordinates(IEnumerable<string> paperrollGrid)
|
||||
{
|
||||
var coordinates = paperrollGrid
|
||||
.Index()
|
||||
.SelectMany(indexedLine => GetCoordinates(indexedLine.Item, indexedLine.Index))
|
||||
.SelectMany((line, xIndex) => GetRollCoordinates(line, xIndex))
|
||||
.ToHashSet();
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
private IEnumerable<Coordinate> GetCoordinates(string gridLine, int xIndex)
|
||||
private IEnumerable<Coordinate> GetRollCoordinates(string gridLine, int xIndex)
|
||||
{
|
||||
var indexedCharacters = gridLine.Index();
|
||||
var validRolls = indexedCharacters.Where(tuple => tuple.Item == '@');
|
||||
|
|
|
|||
|
|
@ -64,7 +64,8 @@ public class Day09 : IPuzzleSolver<long>
|
|||
|
||||
private bool IsRectangleInsideBorders(CoordinatePair[] borders, CoordinatePair rectangle)
|
||||
{
|
||||
return !borders.Any(border => RectangleCrossesBorder(rectangle, border));
|
||||
var bordersCrossed = borders.Any(border => RectangleCrossesBorder(rectangle, border));
|
||||
return !bordersCrossed;
|
||||
}
|
||||
|
||||
private CoordinatePair AsPair(Coordinate a, Coordinate b)
|
||||
|
|
|
|||
Loading…
Reference in New Issue