Last active
December 25, 2015 18:09
-
-
Save tLewisII/7017887 to your computer and use it in GitHub Desktop.
Fibonacci sequence generator in Haskell. Given an upper bounds, will return a list of all numbers in the sequence that are <= the upper bounds.
This file contains 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
module Main where | |
loop :: Integer -> [Integer] -> Integer -> Integer -> [Integer] | |
loop upper list cur prev | |
| (cur == upper) = list ++ [cur] | |
| (cur > upper) = list | |
| otherwise = loop upper (list ++ [cur]) (cur + prev) cur | |
fibSeq :: Integer -> [Integer] | |
fibSeq 0 = [0] | |
fibSeq 1 = [0,1] | |
fibSeq n = loop n [0] 1 0 | |
main = print (fibSeq 10000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment