Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created January 21, 2015 12:37
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 shigemk2/fefa398cb330ad0ca731 to your computer and use it in GitHub Desktop.
Save shigemk2/fefa398cb330ad0ca731 to your computer and use it in GitHub Desktop.
chain :: Integer -> [Integer]
chain 1 = [1]
chain n
| even n = n : chain (n `div` 2)
| odd n = n : chain (n * 3 + 1)
numLongChains :: Int
numLongChains = length (filter isLong (map chain [1..100]))
where isLong xs = length xs > 15
main = do
print $ chain 10
print $ numLongChains
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment