Wow, this one was hard to figure out.
survivor :: Int -> Int -> Int survivor k step = survivor' step [ 1 .. k ] where survivor' :: Int -> [Int] -> Int survivor' step [x] = x survivor' step xs = survivor' step (remove_at step' xs) where step' = reduce_step (length xs) step reduce_step :: Int -> Int -> Int reduce_step len step | step <= len = step | otherwise = reduce_step len (step - len) remove_at :: Int -> [Int] -> [Int] remove_at i xs = (drop i xs) ++ (take (i - 1) xs)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Wow, this one was hard to figure out.
Haskell