You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

18 lines
573 B

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..]