Created
December 5, 2020 18:04
-
-
Save mjgpy3/42957a5db47679bf52b8700cc2a174f3 to your computer and use it in GitHub Desktop.
aoc-2020-day5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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