I made some Fibonacci definitions using Racket (<-- descendant of Scheme <-- dialect of Lisp).

I ran the definitions from within DrRacket (the Racket IDE).

(I think that running the definitions, compiles and loads them.)

Then, I used the definitions from the Racket REPL (read-eval-print loop).

Below, you can see the definitions, and the REPL interactions.

First, I tested, fib, to determine if it functioned correctly.

Next, I timed it for, (fib 100000), 1.739 seconds.

Then, I timed it for, (fib 1000000), 306.756 seconds.

Finally, I calculated the number of digits in, (fib 1000000), 208988.

; code ----------------------------------------------------------------- #lang racket (define big-fib 0) (define (fib-time n) (let ([t1 (current-milliseconds)]) (set! big-fib (fib n)) (let ([t2 (current-milliseconds)]) (/ (- t2 t1) 1000.0)))) (define (fib n) (define (fib-iter a b count) (if (= count 0) b (fib-iter (+ a b) a (- count 1)))) (fib-iter 1 0 n)) ; REPL interactions ---------------------------------------------------- Welcome to DrRacket, version 5.1 [3m]. Language: racket; memory limit: 128 MB. > (fib 0) 0 > (fib 1) 1 > (fib 2) 1 > (fib 3) 2 > (fib 4) 3 > (fib 5) 5 > (fib 6) 8 > (fib 7) 13 > (fib-time 100000) 1.739 > (fib-time 1000000) 306.756 > (define big-fib-string (number->string big-fib)) > (define big-fib-list (string->list big-fib-string)) > (define big-fib-digits (length big-fib-list)) > big-fib-digits 208988 >

## Bookmarks