Skip to content

Instantly share code, notes, and snippets.

@RichardVasquez
Last active December 1, 2021 20:55
Show Gist options
  • Save RichardVasquez/e9b24605038a00b5b7dd1efb3ce2df33 to your computer and use it in GitHub Desktop.
Save RichardVasquez/e9b24605038a00b5b7dd1efb3ce2df33 to your computer and use it in GitHub Desktop.
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

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