A collection of implementations of common algorithms
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

16 lines
296 B

#! /usr/bin/env runghc
-- get the nth fibonnaci number in linear time
import qualified Data.List as L
fibs = L.unfoldr
(\(prev, cur) -> Just (prev, (cur, prev+cur)))
(0, 1)
getNthFib n = fibs !! n
main = do
print $ getNthFib 1
print $ getNthFib 7
print $ getNthFib 100