Created
August 1, 2013 04:20
-
-
Save qoelet/6128384 to your computer and use it in GitHub Desktop.
Fibonacci task
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
-- file: Fib.hs | |
-- Task: Generate first n Fibonacci numbers, then sum it | |
-- fib: given n for the index of the Fibonacci series, return the corresponding value, e.g. fib 9 gives 34 | |
fib :: Int -> Int | |
fib 0 = 0 | |
fib 1 = 1 | |
fib n = fib (n-1) + fib (n-2) | |
-- fib_n: given n for 0..n as the indexes of the Fibonacci series, return the values | |
fib_n :: Int -> [Int] | |
fib_n 0 = [] | |
fib_n n = fib_n (n - 1) ++ [fib n] | |
-- task completion: sum (fib_n n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment