In this problem you have to implement several functions in Haskell. You do not need to ask permission to write auxiliary functions, of course you can!
Write a function absValue :: Int -> Int that,
given an integer, returns its absolute value.
Write a function power :: Int -> Int -> Int
that, given an integer
and a natural
,
returns
the-th
power of
,
that is,
.
Write a function isPrime :: Int -> Bool that,
given a natural, tells whether it is a prime number or not.
Write a function slowFib :: Int -> Int that
returns the
-th
element of the Fibonacci sequence using the recursive algorithm that
defines it
(,
,
for
).
Write a function quickFib :: Int -> Int that
returns the
-th
element of the Fibonacci sequence using a more efficient
algorithm.
Each function scores 20 points.
Input
absValue (-666) power 2 3 isPrime 17 slowFib 5 quickFib 40
Output
666 8 True 5 102334155