29 lines
981 B
C#
29 lines
981 B
C#
namespace AdventOfCodeLibrary._2022
|
|
{
|
|
using AdventOfCodeLibrary.Shared;
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|