Skip to content

Instantly share code, notes, and snippets.

@eccstartup
Created July 25, 2013 11: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 eccstartup/6078905 to your computer and use it in GitHub Desktop.
Save eccstartup/6078905 to your computer and use it in GitHub Desktop.
Fibonacci sequence
> fibonacciList = 1:1:zipWith (+) (tail fibonacciList) fibonacciList
Prime number sequence
> primeList = 2 : let oddList = [3,5..] in filter (\n-> and $ map (\x-> rem n x /= 0) $ takeWhile (\x -> x <= floor (fromIntegral n**(0.5))) primeList) oddList
Binomial coefficients for each order, called Pascal's Triangle
> pascalTriangleList = let fetch2 = (\(m,list) -> let ls = 1:map (\n->sum $ (take 2.drop n) list) [0..floor $ fromIntegral (m-1)/2] in ls ++ (if odd m then drop 1 else id) (reverse ls)) in [1]:[1,1]: (map fetch2 $ zip [1..] $ tail pascalTriangleList)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment