2024-01,02
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user