Here's the sequence version:

import Data.Sequence as Seq

josephus k n = reduce (fromList [1..n])
  where reduce xs
          | Seq.null xs = []
          | otherwise = case viewl (rotate (k-1) xs) of
                                x :< xs' -> x : reduce xs'
        rotate i xs = back >< front
          where (front, back) = Seq.splitAt (i `mod` Seq.length xs) xs

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to