Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
ListOperation
type I = Integer
type M = [I]
g :: (M,I) -> I
g ([],x) = x
g (0:as,x) = f$g (as,x) where f y = y+1
g (a:as,x) = g (clone l1 (g (as,x))++l2,x)
where
(l1,l2) = t$span (a<=) as
t (lis,[]) = (lis,[])
t (lis,y:ys) = (lis++[y],ys)
toMI :: I -> (M,I)
toMI x = (reverse [0..x],x)
clone :: [a] -> Integer -> [a]
clone l 1 = l
clone l k = l ++ clone l (k-1)
listOperation :: I -> I
listOperation = g.toMI
main :: IO()
main = print (iterate listOperation 3 !! 64)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment