Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Day 5 Advent of Code 2020
using System;
using System.Collections.Generic;
using System.Linq;
using AdventOfCode.Library;
namespace AdventOfCode
{
// Day 05 - Massive cleanup
internal static class Program
{
private const bool DoPart1 = true;
private const bool DoPart2 = true;
public static void Main()
{
var data = TextUtility.ReadLines(removeBlank: true);
var seats =
(
from s in data
let bin = s.Replace('F', '0').Replace('B', '1').Replace('R', '1').Replace('L', '0')
select Convert.ToInt32(bin, 2)
)
.ToList();
seats.Sort();
data.Process(DoPart1, 1, seats, Solver1);
data.Process(DoPart2, 2, seats, Solver2);
}
private static string Solver1(List<string> arg1, object arg2)
{
var seats = (List<int>) arg2;
return $"{seats.Max()}";
}
private static string Solver2(List<string> arg1, object arg2)
{
var seats = (List<int>) arg2;
long pyramid = seats.Last() * (seats.Last() + 1) / 2 -
(seats.First() - 1) * seats.First() / 2;
long total = seats.Sum();
return $"{pyramid - total}";
}
}
}
@RichardVasquez
Copy link
Author

RichardVasquez commented Dec 6, 2020

Took me a while to realize the whole string is just a binary value with dual characters for each 1/0, and there's no need to partition it by seat/row.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment