Skip to content

Commit

Permalink
Day 9 - move reducing logic to ParseInput
Browse files Browse the repository at this point in the history
  • Loading branch information
eduherminio committed Dec 9, 2023
1 parent 73f137e commit a75e7d0
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/AoC_2023/Day_09.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class Day_09 : BaseDay
{
private readonly List<List<int>> _input;
private readonly List<List<List<int>>> _input;

public Day_09()
{
Expand All @@ -13,9 +13,9 @@ public override ValueTask<string> Solve_1()
{
int result = 0;

foreach (var input in _input)
foreach (var sequences in _input)
{
foreach (var sequence in ReduceToZero(input))
foreach (var sequence in sequences)
{
result += sequence[^1];
}
Expand All @@ -28,10 +28,8 @@ public override ValueTask<string> Solve_2()
{
int result = 0;

foreach (var input in _input)
foreach (var sequences in _input)
{
var sequences = ReduceToZero(input);

for (int i = 0; i < sequences.Count; i++)
{
result += (i % 2 == 1)
Expand All @@ -45,7 +43,7 @@ public override ValueTask<string> Solve_2()

private static List<List<int>> ReduceToZero(List<int> input)
{
List<List<int>> sequences = new(input.Count) { new(input) };
List<List<int>> sequences = new(input.Count) { input };

while (true)
{
Expand Down Expand Up @@ -75,13 +73,13 @@ private static List<List<int>> ReduceToZero(List<int> input)
return sequences;
}

private IEnumerable<List<int>> ParseInput()
private IEnumerable<List<List<int>>> ParseInput()
{
var file = new ParsedFile(InputFilePath);

while (!file.Empty)
{
yield return file.NextLine().ToList<int>();
yield return ReduceToZero(file.NextLine().ToList<int>());
}
}
}

0 comments on commit a75e7d0

Please sign in to comment.