1 module Main(main) where
3 import Prelude hiding (length, take, drop)
15 part1 = print $ 2 * (input - 2 ^ (toInteger (floor $ logBase 2 (fromIntegral input)))) + 1
18 part2 = print $ flip index 0 $ presentSteps initial
20 presentSteps :: Seq Int -> Seq Int
22 | isFinished elves = elves
23 | otherwise = presentSteps $ next elves
26 initial = fromList [1..input]
28 isFinished :: Seq Int -> Bool
29 isFinished elves = length elves == 1
31 next :: Seq Int -> Seq Int
32 next elves = prefix >< (midfix |> suffix)
34 target = length elves `quot` 2
35 prefix = drop 1 $ take target elves
36 midfix = drop (target+1) elves
37 suffix = index elves 0