blob: c018203c0a1a923dff2b009e37352ef313fb292d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
module Main where
data Direction = Upper | Lower
doHalf :: [Direction] -> (Int, Int) -> Int
doHalf ls start = fst $ foldl fn start ls
where fn (l, u) Lower = (l, (u+l) `div` 2)
fn (l, u) Upper = ((u+l) `div` 2 + 1, u)
doValidate :: String -> Int
doValidate s = row * 8 + col
where row = flip doHalf (0, 127) $ map readDir (take 7 s)
col = flip doHalf (0, 7) $ map readDir (drop 7 s)
readDir :: Char -> Direction
readDir c
| c `elem` "FL" = Lower
| otherwise = Upper
main :: IO ()
main = do
n <- lines <$> readFile "input/05"
let valids = map doValidate n
ans1 = maximum valids
print ans1
print $ sum [minimum valids .. ans1] - sum valids
|