Skip to content

Instantly share code, notes, and snippets.

@akhileshs
Created October 7, 2015 18:48
Show Gist options
  • Select an option

  • Save akhileshs/edb42003ea9be8876154 to your computer and use it in GitHub Desktop.

Select an option

Save akhileshs/edb42003ea9be8876154 to your computer and use it in GitHub Desktop.
Haskell Trial
{-
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