Skip to content

Instantly share code, notes, and snippets.

@Joseph-Bake
Created July 4, 2017 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Joseph-Bake/029982db9dad183845b9a5299baf64f1 to your computer and use it in GitHub Desktop.
Save Joseph-Bake/029982db9dad183845b9a5299baf64f1 to your computer and use it in GitHub Desktop.
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)
gg :: ([M],I) -> I
gg ([],x) = x
gg ([list],x) = g (list,x)
gg ([]:bs,x) = gg (bs,x)
gg ((0:as):bs,x) = nListOperation (toInteger$length ((0:as):bs)-1) (gg (as:bs,x))
gg ((a:as):bs,x) = gg (llist:bs,x)
where
llist = clone l1 (gg (as:bs,x)) ++ l2
(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)
toMMI :: I -> I -> ([M],I)
toMMI n x = (replicate (fromIntegral n) (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
nListOperation :: I -> I -> I
nListOperation 1 x = listOperation x
nListOperation n x = gg (toMMI n x)
listOperation2 :: I -> I
listOperation2 x = nListOperation x x
main :: IO()
main = print (iterate listOperation2 3 !! 64)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment