I’ve made a basic program that output Fibonacci sequence for whatever length “n”.
Here’s the code I have:
(define (fibh n)
(if (< n 2)
n
(+ (fibh (- n 1)) (fibh (- n 2)))))
(define (fib n)
(do ((i 1 (+ i 1)))
((> i n))
(display (fibh i))))
It will output, for example, 112358.
What I want is a list such as (1 1 2 3 5 8).
Any explanation how to do this would be greatly appreciated.
would do the trick. If you don’t want to enumerate the integers by hand, then implement a simple recursive function that will do that for you, like:
(Note: this is not tail-recursive, but with that algorithm to compute the Fibonacci numbers, that’s not your prime concern.)