Q1: Virahanka-Fibonacci
Write a function that returns the n-th Virahanka-Fibonacci number.
(define (vir-fib n)
(cond
((< n 2) n)
(else (+ (vir-fib (- n 1)) (vir-fib (- n 2))))
)
)
(expect (vir-fib 2) 1)
(expect (vir-fib 10) 55)
(expect (vir-fib 1) 1)
Q2: List Making
Let’s make some Scheme lists. We’ll define the same list with list, quote, and cons. The following list was visualized using the draw feature of code.cs61a.org.
First, use list:
(define with-list
(list
(list 'a 'b) 'c 'd (list 'e)
)
)
(draw with-list)
Now use quote. What differences are there?
(define with-quote
'(
(a b) c d (e)
)
)
(draw with-quote)
Now try with cons. For convenience, we’ve defined a helpful-list and another-helpful-list:
(define helpful-list
(cons 'a (cons 'b nil)))
(draw helpful-list)
(define another