From 19975730a539af00664d6b8a067f943cceb7ee2a Mon Sep 17 00:00:00 2001 From: Martin Potier Date: Mon, 7 Dec 2020 12:11:12 +0200 Subject: [PATCH] Day 5 - Part 2 --- day5/main.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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