Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Homework number 4 - fibonacci sussquences.

Name: Anonymous 2010-01-19 4:00

Consider the generalized fibonacci sequences:
4, 1, 5, 6, 11, 17, 28, ...
3, 2, 5, 7, 12, 19, 31, ...
Write a program that takes two numbers as input and prints as many Sussmans as the tenth number in the resulting fibonacci sequence.
USE RECURSION.

Name: Anonymous 2010-01-19 21:38

>>22
Lifted from SICP:
(define (general-fib b a p q n)
  (cond ((= n 0) b)
        ((even? n)
         (general-fib b
                      a
                      (+ (square p) (square q))
                      (+ (* 2 p q) (square q))
                      (/ n 2)))
        (else (general-fib (+ (* b p) (* a q))
                           (+ (* b q) (* a q) (* a p))
                           p
                           q
                           (dec n)))))
(map (lambda(x) (general-fib 5 6 0 1 x)) (build-list 10))

(5 6 11 17 28 45 73 118 191 309)

Also, fuck, I was >>21

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List