Skip to content

Instantly share code, notes, and snippets.

@mjgpy3
Created December 5, 2020 18:04
Show Gist options
  • Select an option

  • Save mjgpy3/42957a5db47679bf52b8700cc2a174f3 to your computer and use it in GitHub Desktop.

Select an option

Save mjgpy3/42957a5db47679bf52b8700cc2a174f3 to your computer and use it in GitHub Desktop.
aoc-2020-day5
module Main where
import Data.List (foldl')
parseBinary = foldl' (\acc v -> acc*2 + (if v then 1 else 0)) 0
seatId = parseBinary . map (`elem` "BR")
main = do
raw <- readFile "./d5.txt"
print $ maximum $ map seatId $ words raw
module Main where
import Data.List (foldl', sort)
parseBinary = foldl' (\acc v -> acc*2 + (if v then 1 else 0)) 0
seatId = parseBinary . map (`elem` "BR")
s x y z = x z (y z)
pairwise = s zip tail
-- Original solution was a little less cutesy
mySeatId =
(+) 1 . fst . head . filter (\(a, b) -> a == b - 2) . pairwise . sort . map seatId
main = do
raw <- readFile "./d5.txt"
print $ mySeatId $ words raw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment