Skip to content

Instantly share code, notes, and snippets.

@Joseph-Bake
Created July 17, 2017 14:42
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/afab33c823d81c4ccc929ce413f01f86 to your computer and use it in GitHub Desktop.
Save Joseph-Bake/afab33c823d81c4ccc929ce413f01f86 to your computer and use it in GitHub Desktop.
ベクレミシェフの虫
type I = Integer
g :: [I] -> I -> I
g [] x = x-1
g (0:as) x = g as (f x) where f y = y+1
g (a:as) x = g (clone l1' (x+1)++l2) (x+1)
where
clone list 1 = list
clone list k = list ++ clone list (k-1)
(l1,l2) = span (a<=) as
l1' = (a-1) : l1
main :: IO()
main = print (worm 2) where worm x = g [x] 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment