Solve day 5, parts 1 and 2

main
Gaël Depreeuw 4 years ago
parent 1cb7efa11a
commit 324e47c7b4
Signed by: Mithror
GPG Key ID: 8AB218ABA4867F78
  1. 2
      AdventOfCode2020.cabal
  2. 2
      Main.hs
  3. 900
      input/day5
  4. 30
      src/Day5.hs

@ -17,7 +17,7 @@ maintainer: gael@depreeuw.dev
extra-source-files: CHANGELOG.md, README.md
library
exposed-modules: Day1, Day2, Day3, Day4
exposed-modules: Day1, Day2, Day3, Day4, Day5
-- other-modules:
-- other-extensions:
build-depends: base ^>=4.13.0.0

@ -4,6 +4,7 @@ import Day1 (day1)
import Day2 (day2)
import Day3 (day3)
import Day4 (day4)
import Day5 (day5)
main :: IO ()
main = do
@ -11,3 +12,4 @@ main = do
day2
day3
day4
day5

@ -0,0 +1,900 @@
BFFFFBBRRL
FBBBBBBRRL
BBBFFBBRRR
BFFFFFFLRL
FBFFBFBRRR
BFFBFFBLRR
FFBBBFBRRR
BBFBBBBLRL
FBFFBFFLRL
BFFFBBFLLL
FBFFFFFRLL
FBFFBFFRRL
BBBFBFBRRL
BFFBFFFLLL
FBFFFFFLLL
BFFFBBFLLR
FBBFFBFRRR
FFBBFBFLRR
FFFBBBFLRL
FFBFBBBRRL
FBFBBBBLLR
BBBFFFBLLR
FBBBFFFLLL
FFBFBFFRLR
FBFBBBFLLR
BBBFBBBRRR
FBBFFFBLRR
FBBFFFBLLR
BFBFFBBLLL
BBFFFFFRLR
BBFBBFFRRL
BBBBFBFRRR
BFFFFBFRRR
FBFFFFBLLR
FFBFBFBRLL
FBFFFFBLRL
BFFFFFFLLL
BFBBFBBLRR
FFFBBBBRRL
BBFFFFBLRL
FFFBBFBRLL
BBBBFFBRRR
FBBBBBFRLL
BFFBFBFRLL
FBFFBFFLLL
FBBBBBBRLL
FFFBBBFRRL
BBFFFFBRRR
FFBFBFFLLR
FBBFFFFRRR
BFFFFFBRRL
BBFFFBBRLR
BBBBFFFRLL
BFFFFBFRLR
BFBBBBFLRL
FFBFB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FFBBLRL
BFFFFBFLLL
BBBFFBFLLR
FFBBBFFRLL
BFFBBFBLLL
BBBFBBFLLL
BBFFBBFRRR

@ -0,0 +1,30 @@
module Day5 (day5) where
import Data.List (sort, (\\))
getRow :: String -> Integer
getRow = snd . foldr go (1, 0)
where
go 'F' (m, s) = (m * 2, s)
go 'B' (m, s) = (m * 2, s + m)
go _ _ = error "not possible"
getCol :: String -> Integer
getCol = snd . foldr go (1, 0)
where
go 'L' (m, s) = (m * 2, s)
go 'R' (m, s) = (m * 2, s + m)
go _ _ = error "not possible"
getSeat :: String -> (Integer, Integer)
getSeat s = let (row, col) = take 3 <$> splitAt 7 s in (getRow row, getCol col)
day5 :: IO ()
day5 = do
r <- readFile "./input/day5"
let m = lines r
putStr "[Day 5-1] max id: "
let ids = sort $ map ((\(a, b) -> 8 * a + b) . getSeat) m
print . maximum $ ids
putStr "[Day 5-2] my id: "
print . head $ (enumFrom (head ids) \\ ids)
Loading…
Cancel
Save