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

28 lines
870 B
C#

namespace AdventOfCodeLibrary._2022
{
using AdventOfCodeLibrary.Shared;
public class Day04Part2 : IAnswerable
{
public int Year { get; set; } = 2022;
public int Day { get; set; } = 4;
public int Part { get; set; } = 2;
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])
.ToArray())
.Count(sections => sections[0][1] >= sections[1][0])
.ToString();
}
}
}