-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
25 lines (18 loc) · 898 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using System.Text.RegularExpressions;
using AdventOfCode.Common;
var lines = Resources.GetInputFileLines();
var regex = new Regex(@"(\d+)-(\d+),(\d+)-(\d+)");
var assignments = lines
.Select(line => regex.Match(line).Groups)
.Select(g =>
(new Assignment(int.Parse(g[1].Value), int.Parse(g[2].Value)),
new Assignment(int.Parse(g[3].Value), int.Parse(g[4].Value))))
.Select(a => a.Item1.Start <= a.Item2.Start ? a : (a.Item2, a.Item1))
.ToList();
var inclusiveAssignments = assignments
.Where(a => (a.Item2.Start <= a.Item1.End && a.Item2.End <= a.Item1.End) || a.Item2.Start == a.Item1.Start);
var overlappingAssignments = assignments
.Where(a => a.Item2.Start <= a.Item1.End);
Console.WriteLine($"Part 1: {inclusiveAssignments.Count()}");
Console.WriteLine($"Part 2: {overlappingAssignments.Count()}");
file record Assignment(int Start, int End);