AoC/2020/day05/day05.hs
2020-12-17 19:19:48 +01:00

19 lines
573 B
Haskell

import Control.Lens
import Data.List
import Control.Monad
import Data.Ord
main :: IO ()
main = do
input <- lines <$> readFile "input"
print $ last $ seatList input
print $ minimumBy (comparing (uncurry (-)) ) $ ap zip tail $ seatList input
seatList :: [String] -> [Int]
seatList = sort . map ((uncurry (+) . (_2 *~ 8)) . parseSeat)
parseSeat :: String -> (Int,Int)
parseSeat line = (parseOn 'R' cols,parseOn 'B' rows)
where (cols,rows) = splitAt 3 (reverse line)
parseOn c = sum . map (round . (**) 2 . fst) . filter (\(_,x)->x==c) . zip [0..]