Skip to content

Instantly share code, notes, and snippets.

@motokiee
Created October 12, 2015 06:18
Show Gist options
  • Save motokiee/d8b27b02aea5c5f92c51 to your computer and use it in GitHub Desktop.
Save motokiee/d8b27b02aea5c5f92c51 to your computer and use it in GitHub Desktop.
コラッツ列とflipをラムダで書いたもの #CodePiece
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 (\xs -> length xs > 15) (map chain [1..100]))
flip' :: (a -> b -> c) -> b -> a -> c
flip f = \x y -> f y x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment