2024-01,02

This commit is contained in:
2025-11-16 17:47:14 -08:00
parent 68d81019e8
commit 8f5087ac36
3 changed files with 56 additions and 8 deletions

View File

@@ -4,7 +4,21 @@ public class Day02 : ISolution
{
public void Run()
{
var _ = File.ReadAllText("input/02");
Console.WriteLine("The solution for day 02 is not implmented yet");
var input = File.ReadAllText("input/02")
.Split('\n')
.Select(line => line.Split(' ')
.Select(int.Parse)
.ToList())
.ToList();
Console.WriteLine(PartOne(input));
}
private static int PartOne(List<List<int>> list) {
return list.Select(line => Enumerable.Range(1, Math.Max(0, line.Count - 1))
.Select(i => line[i] - line[i - 1])
.ToList())
.Where(diffs => diffs.All(d => d > 0) || diffs.All(d => d < 0))
.Count(diffs => !diffs.Any(d => Math.Abs(d) is < 1 or > 3));
}
}