Day 5 - Part 2

This commit is contained in:
Martin Potier 2020-12-07 12:11:12 +02:00
parent 640efa334b
commit 19975730a5
No known key found for this signature in database
GPG key ID: D4DD957DBA4AD89E

View file

@ -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