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

Pages: 1-

best way to do fibs in lisp

Name: Anonymous 2012-02-18 1:18

i see so many, but which is best?

Name: Anonymous 2012-02-18 1:37

If it's Lisp, it's not the BEST

Name: Anonymous 2012-02-18 2:25

The best one uses continuations, delayed evaluation, a DSL made of macros, a Y combinator derived from the SKI combinators, and Church numerals just to show off the POWER OF LISP.

Name: Anonymous 2012-02-18 3:09

Lisp is shit.

Name: Anonymous 2012-02-18 20:14

The method that also does factorials

Name: Anonymous 2012-02-18 20:35

the only ``fibs'' are:
1. lisp is not shit
2. my other car is not a cdr

Name: Anonymous 2012-02-19 8:44

(define (fib n)
  (define (fib-iter a b p q count)
    (cond ((zero? count) b)
          ((even? count)
           (fib-iter a
                     b
                     (+ (* p p) (* q q))
                     (+ (* 2 p q) (* q q))
                     (/ count 2)))
          (else (fib-iter (+ (* b q) (* a q) (* a p))
                          (+ (* b p) (* a q))
                          p
                          q
                          (- count 1)))))
  (fib-iter 1 0 0 1 n))


O(log n)

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