1 import Prelude hiding (length, take, drop)
13 part1 = print $ 2 * (input - 2 ^ (toInteger (floor $ logBase 2 (fromIntegral input)))) + 1
16 part2 = print $ flip index 0 $ presentSteps initial
18 presentSteps :: Seq Int -> Seq Int
20 | isFinished elves = elves
21 | otherwise = presentSteps $ next elves
24 initial = fromList [1..input]
26 isFinished :: Seq Int -> Bool
27 isFinished elves = length elves == 1
29 next :: Seq Int -> Seq Int
30 next elves = prefix >< (midfix |> suffix)
32 target = length elves `quot` 2
33 prefix = drop 1 $ take target elves
34 midfix = drop (target+1) elves
35 suffix = index elves 0