You board your plane only to discover a new problem: you dropped your boarding pass! You aren't sure which seat is yours, and all of the flight attendants are busy with the flood of people that suddenly made it through passport control.
You write a quick program to use your phone's camera to scan all of the nearby boarding passes (your puzzle input); perhaps you can find your seat through process of elimination.
Read the full puzzle.
using System;
using System.Collections.Generic;
using System.Linq;
namespace AdventOfCode.Y2020.Day05;
[ProblemName("Binary Boarding")]
class Solution : Solver {
public object PartOne(string input) => Seats(input).Max();
public object PartTwo(string input) {
var seats = Seats(input);
var (min, max) = (seats.Min(), seats.Max());
return Enumerable.Range(min, max - min + 1).Single(id => !seats.Contains(id));
}
HashSet<int> Seats(string input) =>
input
.Replace("B", "1")
.Replace("F", "0")
.Replace("R", "1")
.Replace("L", "0")
.Split("\n")
.Select(row => Convert.ToInt32(row, 2))
.ToHashSet();
}
Please ☆ my repo if you like it!