AdventOfCode/AdventOfCode.Solutions/2022/Day 04/Day04Part1.cs
Rob 3846b42b7e Massive code base change
partial completion of day 3
2023-12-03 19:09:26 +01:00

27 lines
945 B
C#

namespace AdventOfCode.Solutions._2022
{
public class Day04Part1 : Answerable
{
public override int Year { get; set; } = 2022;
public override int Day { get; set; } = 4;
public override int Part { get; set; } = 1;
public override string GetAnswer(byte[] data)
{
return GetAsStringArray(data)
.Where(line => !string.IsNullOrWhiteSpace(line))
.Select(line =>
line.Split(',')
.Select(s => s.Trim())
.Select(s => s.Split('-')
.Select(s => Convert.ToInt32(s))
.ToArray())
.OrderBy(s => s[0])
.OrderByDescending(s => s[1])
.ToArray())
.Count(sections => sections[0][0] <= sections[1][0] && sections[0][1] >= sections[1][1])
.ToString();
}
}
}