Removed language extension
[advent-of-code-16.git] / advent19.hs
1 import Prelude hiding (length, take, drop)
2 import Data.Sequence
3
4 -- input = 5
5 input = 3012210
6
7 main :: IO ()
8 main = do
9 part1
10 part2
11
12 part1 :: IO ()
13 part1 = print $ 2 * (input - 2 ^ (toInteger (floor $ logBase 2 (fromIntegral input)))) + 1
14
15 part2 :: IO ()
16 part2 = print $ index (presentSteps initial) 0
17
18 presentSteps :: Seq Int -> Seq Int
19 presentSteps elves
20 | isFinished elves = elves
21 | otherwise = presentSteps $ next elves
22
23 initial :: Seq Int
24 initial = fromList [1..input]
25
26 isFinished :: Seq Int -> Bool
27 isFinished elves = length elves == 1
28
29 next :: Seq Int -> Seq Int
30 next elves = prefix >< (midfix |> suffix)
31 where
32 target = length elves `quot` 2
33 prefix = drop 1 $ take target elves
34 midfix = drop (target+1) elves
35 suffix = index elves 0