Browse Source

Day 5

master
shu 10 months ago
parent
commit
f9ea5815ff
  1. 18
      2020/day05/day05.hs
  2. 774
      2020/day05/input
  3. 3
      2020/day05/testinput

18
2020/day05/day05.hs

@ -0,0 +1,18 @@
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..]

774
2020/day05/input

@ -0,0 +1,774 @@
FFFBFBFLRR
FFBBFFFRLL
FBFBFFBRLR
FFFBBFBRRL
BFFFBBFRRL
FFBFBFFLLR
FBFBBFFRLL
FFBBFBBLLL
BFFFBBFLLR
FBBFFBBRLR
FBFBBBBLLL
BFFBBBFLLR
BBFFBFBLRR
FBBBFFBRRL
FFFBFBBLRL
FFBFBFBRLR
FBBBBFFRRL
FBBBBFBLLR
BFBBBBFRRR
BFBFFBBLRL
FBBFBBFRLL
FFBBBFBRLR
FBBFFFBRLL
FBFBBFBLRR
FFFBBBFLLL
FBFFBBFLRL
BFFFBFFLLR
FBFBBBBLRL
FBBFBFFRLR
FBFBBBBRLL
FFBFFBFLLR
BFFBFFBRLL
FBBBBFFLRL
BFFBFBBRLR
FFBFFFFLLR
BBFFBBFRLR
BFBFBBBRRL
BFFBBBBLRR
FFBBBBBRLL
FFFBBFFRLR
BBFFFFBLRL
BFBBFBFRRL
BBFFBBFRRL
FBFFFFBRLR
FBBFBBBRLR
BBFBFFFLLL
BFBFBBBRLL
BFFFFFFLRL
FBFBFBFRRR
BBFFFFFLRR
FFFBBFBLLR
FBFFBFBRLL
BFBBFBFLLR
FFBFBFFLRL
BFBFFBFRRR
F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