Created
March 28, 2011 16:23
-
-
Save dreamiurg/890765 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
factorial1 n = if n == 0 then 1 else n * factorial1 (n-1) | |
factorial2 0 = 1 | |
factorial2 n = n * factorial2 (n-1) | |
factorial3 n = foldr (*) 1 [1..n] | |
factorial4 = foldr (*) 1 . enumFromTo 1 | |
sumList [] = 0 | |
sumList (x:xs) = x + sumList xs | |
lenList [] = 0 | |
lenList (_:xs) = 1 + lenList xs | |
sumPositive [] = 0 | |
sumPositive (x:xs) | x > 0 = x + sumPositive xs | |
sumPositive (_:xs) = sumPositive xs | |
qsort [] = [] | |
qsort (x:xs) = qsort [y | y <- xs, y < x] ++ [x] ++ qsort [y | y <- xs, y >= x] | |
primes = 2 : [ k | k <- [3..], isPrime k ] | |
isPrime k = all (\n -> k `mod` n /= 0) $ takeWhile (\n -> n^2 <= k) primes | |
fibonacci = 1 : 1 : zipWith (+) fibonacci (tail fibonacci) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment