taocp

taocp sandbox.
git clone git://git.ricketyspace.net/taocp.git
Log | Files | Refs

commit 5778a7251f6a09a74bb896503c11f2f686b1f09b
parent 6afbb4684067339b28dff02ac8252ab932e00a59
Author: rsiddharth <s@ricketyspace.net>
Date:   Wed, 25 Jan 2017 03:50:34 +0000

(taocp utils math) Add fibonacci functions.

* guile/taocp/utils/math.scm (fib, fib-range): New functions.

Diffstat:
guile/taocp/utils/math.scm | 18++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/guile/taocp/utils/math.scm b/guile/taocp/utils/math.scm @@ -2,8 +2,10 @@ ;;;; under gnu general public license version 3 or higher. (define-module (taocp utils math) - #:export (compute-exp1-n)) - + #:use-module (srfi srfi-1) + #:export (compute-exp1-n + fib + fib-range)) (define (compute-exp1-n fx n) "Evaluate function FX for `x` equals 1 to N and return all results @@ -15,3 +17,15 @@ For instance `(lambda (x) (* x x))` is a valid FX. " (cond ((= n 0) '()) (else (cons (fx n) (compute-exp1-n fx (1- n)))))) + +(define (fib n) + "Returns Fibonacci of N." + (cond ((= n 0) 0) + ((= n 1) 1) + (else (+ (fib (- n 1)) (fib (- n 2)))))) + +(define (fib-range start end) + "Returns Fibonacci sequence between START and END." + (let ((f (lambda (x) (cons x (fib x)))) + (count (1+ (- end start )))) + (map f (iota count start))))