AdventOfCode/Advent Of Code Library/2022/Day 04/Day04Part1.cs

29 lines
956 B
C#

namespace AdventOfCodeLibrary._2022
{
using AdventOfCodeLibrary.Shared;
public class Day04Part1 : IAnswerable
{
public int Year { get; set; } = 2022;
public int Day { get; set; } = 4;
public int Part { get; set; } = 1;
public string GetAwner(byte[] data)
{
return ByteHelper.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();
}
}
}