
You can do something like
fibTable n = [ show x ++ "\t" ++ show y | (x,y) <- zip [1..] (fibs n) ]
where
fibs n = list containing fibonacci numbers from fib(1) to fib(n)
On 11 November 2015 at 18:57, Roelof Wobben
Op 11-11-2015 om 14:11 schreef Sumit Sahrawat, Maths & Computing, IIT (BHU):
Hint 1) fib n = fib (n - 1) + fib (n - 2), with proper base cases
oke, so use recursion. No problem.
Hint 2) use mapM_ to print a list of pairs, where the list is created by zipping [1..] with the list of fibonacci numbers
mapM_ is not explained in the first 5 chapters of Craft of functional programming,
Can not both or one of the two be done with list comprehension because all former exercises uses list comprehension
Roelof
On 11 November 2015 at 18:29, Roelof Wobben
wrote: Hello,
I have this exercise :
Define a function fibTable :: Integer -> String which produces a table of Fibonacci numbers. For instance, the effect of putStr (fibTable 6) should be n fib n 0 0 1 1 2 1 3 2 4 3 5 5 6 8
1) Can somone give me any pointers how to calculate the fibb numbers with list comprehension. I know that the fib numbers are (n -1) + n
2) Can someone give me any pointers how to write the outcome of every run
Roelof
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- Regards
Sumit Sahrawat
_______________________________________________ Beginners mailing listBeginners@haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Geen virus gevonden in dit bericht. Gecontroleerd door AVG - www.avg.com Versie: 2015.0.6176 / Virusdatabase: 4460/10979 - datum van uitgifte: 11/11/15
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- Regards Sumit Sahrawat