diff --git a/day5/main.hs b/day5/main.hs index 6dceeaa..c1370d9 100755 --- a/day5/main.hs +++ b/day5/main.hs @@ -6,6 +6,7 @@ {-# LANGUAGE OverloadedStrings #-} -- import Debug.Trace (trace) +import Data.List (sort) binaryPartitionWalker :: String -> Int -> Int -> (String, Int, Int) binaryPartitionWalker ('F':s) begin end = @@ -29,6 +30,9 @@ seatID str = row * 8 + seat solvePart1 :: [String] -> Int solvePart1 = maximum . (map seatID) +solvePart2 :: [String] -> Int +solvePart2 = fst . head . (filter (\(x,y) -> x /= y)) . (zip [13..]) . sort . (map seatID) + main :: IO () main = do putStrLn "Day 5 - Part 1" @@ -36,6 +40,8 @@ main = do print $ seatID "BFFFBBFRRR" print $ seatID "FFFBBBFRRR" print $ seatID "BBFFBBFRLL" - putStrLn $ "Solution of part 1" input <- lines <$> readFile "day5/input" + putStrLn $ "Solution of part 1" print $ solvePart1 input + putStrLn $ "Solution of part 2" + print $ solvePart2 input