Created
October 7, 2015 18:48
-
-
Save akhileshs/edb42003ea9be8876154 to your computer and use it in GitHub Desktop.
Haskell Trial
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
| {- | |
| FirstScript.hs | |
| Akhilesh . S | |
| -} | |
| -- The Value size is an integer (Int), defined to be | |
| -- the sum of twelve and thirteen. | |
| fac :: Int -> Int | |
| fac n | |
| | n == 0 = 1 | |
| | n > 0 = fac (n - 1) * n | |
| | otherwise = error "fac only defined on natural numbers" | |
| power2 :: Int -> Int | |
| power2 n | |
| | n == 0 = 1 | |
| | n > 0 = 2 * power2 (n - 1) | |
| sumFacs :: Int -> Int | |
| sumFacs n | |
| | n == 0 = 1 | |
| | n > 0 = sumFacs (n - 1) + fac n | |
| sumFun :: (Int -> Int) -> Int -> Int | |
| sumFun f n | |
| | n == 0 = f 0 | |
| | n > 0 = sumFun f (n - 1) + f n | |
| regions :: Int -> Int | |
| regions n | |
| | n == 0 = 1 | |
| | n > 0 = regions (n - 1) + n | |
| fib :: Int -> Int | |
| fib n | |
| | n == 0 = 0 | |
| | n == 1 = 1 | |
| | n > 1 = fib (n - 2) + fib (n - 1) | |
| remainder :: Int -> Int -> Int | |
| divide :: Int -> Int -> Int | |
| remainder m n | |
| | m < n = m | |
| | otherwise = remainder (m - n) n | |
| divide m n | |
| | m < n = 0 | |
| | otherwise = 1 + divide (m - n) n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment