Skip to content

Instantly share code, notes, and snippets.

@piksel
Created December 5, 2020 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piksel/6e84056a60d234845f9cd09c9ca33d71 to your computer and use it in GitHub Desktop.
Save piksel/6e84056a60d234845f9cd09c9ca33d71 to your computer and use it in GitHub Desktop.
using System.IO;
using System.Collections.Immutable;
using System.Linq;
using static System.Linq.Enumerable;
using static ConLib.PrettyConsole;
var seats = new bool[0b1111111111];
foreach (var line in File.ReadLines("input.txt"))
seats[line.Select(s => "BR".Contains(s) ? 1 : 0).Aggregate(0, (a, b) => b | a << 1)] = true;
var taken = seats.Select((s, i) => s ? i : -1).Where(i => i >= 0).ToImmutableArray();
var max = taken.Max();
var min = taken.Min();
var seat = Range(min, max - min).Single(s => !taken.Contains(s));
WriteLine($"Silver: {max}");
WriteLine($"Gold: {seat}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment