Files
advent-of-code/2024/Day02.cs
2025-11-16 17:47:14 -08:00

25 lines
712 B
C#

namespace _2024;
public class Day02 : ISolution
{
public void Run()
{
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));
}
}