zurück   Startseite   Blog Buchregal Buchregal, eBooks Twitter E-Mail

 

Fibonacci numbers

; Fibonacci numbers are given by f(n)=f(n-1)+f(n-2).

(define (fiboCalc n1 n2 startfibo maxfibo)
 (if (< startfibo maxfibo)
  (begin
  (display ", f(")
  (display startfibo)
  (display "): ")
  (display n2)

  (fiboCalc n2 (+ n2 n1) (+ startfibo 1) maxfibo)
)  n2 ))

 

(define (fibo n)
   ( if (= n 0)
       1
       (begin
     (display "f(0): 1")
      (fiboCalc 1 1 1 n))
))


(fibo 2)
f(0): 1, f(1): 1
;Value: 2

(fibo 20)
f(0): 1, f(1): 1, f(2): 2, f(3): 3, f(4): 5, f(5): 8, f(6): 13, f(7): 21, f(8): 34, f(9): 55, f(10): 89, f(11): 144, f(12): 233, f(13): 377, f(14): 610, f(15): 987, f(16): 1597, f(17): 2584, f(18): 4181, f(19): 6765
;Value: 10946

 

 

25. März 2019     | mit scheme | scheme | lisp | old data

zurück

 

     

Startseite | Impressum | Datenschutz