Refactor Day04 to use Index() extension method
This commit is contained in:
parent
0d028c4282
commit
31caf429ca
|
|
@ -4,7 +4,7 @@ namespace AoC_2025.Tests;
|
|||
|
||||
public class Day05Test
|
||||
{
|
||||
private readonly IPuzzleSolver<long> _sut;
|
||||
private readonly Day05 _sut;
|
||||
private static readonly string rootPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
||||
private readonly string TestInputPath = @$"{rootPath}\AoC-PuzzleInputs\2025\Test\day05.txt";
|
||||
private readonly string ProdInputPath = @$"{rootPath}\AoC-PuzzleInputs\2025\Prod\day05.txt";
|
||||
|
|
@ -44,4 +44,20 @@ public class Day05Test
|
|||
|
||||
Assert.Equal(369761800782619, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Part02Again_Test_equals_14()
|
||||
{
|
||||
var actual = _sut.SolvePart2Again(TestInputPath);
|
||||
|
||||
Assert.Equal(14, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Part02Again_Prod_equals_369761800782619()
|
||||
{
|
||||
var actual = _sut.SolvePart2Again(ProdInputPath);
|
||||
|
||||
Assert.Equal(369761800782619, actual);
|
||||
}
|
||||
}
|
||||
|
|
@ -55,16 +55,17 @@ public class Day04 : IPuzzleSolver<long>
|
|||
private HashSet<Coordinate> GetRollCoordinates(IEnumerable<string> paperrollGrid)
|
||||
{
|
||||
var coordinates = paperrollGrid
|
||||
.SelectMany((gridLine, xIndex) => GetCoordinates(gridLine, xIndex))
|
||||
.Index()
|
||||
.SelectMany(indexedLine => GetCoordinates(indexedLine.Item, indexedLine.Index))
|
||||
.ToHashSet();
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
private IEnumerable<Coordinate> GetCoordinates(string gridLine, int xIndex)
|
||||
{
|
||||
var indexedCharacters = gridLine.Select((character, yIndex) => (character, yIndex));
|
||||
var validRolls = indexedCharacters.Where(tuple => tuple.character == '@');
|
||||
var rollCoordinates = validRolls.Select(tuple => (xIndex, tuple.yIndex));
|
||||
var indexedCharacters = gridLine.Index();
|
||||
var validRolls = indexedCharacters.Where(tuple => tuple.Item == '@');
|
||||
var rollCoordinates = validRolls.Select(tuple => (xIndex, tuple.Index));
|
||||
return rollCoordinates;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue