Arc Forumnew | comments | leaders | submitlogin
1 point by akkartik 2837 days ago | link | parent

Here's the fast fibonacci from SICP 1.19 in wart[1]:

  def fib(n)
    (fib_iter 1 0 0 1 n)

  def fib_iter(a b p q n)
    (if
      (iso n 0)
        b
      even?.n
        (fib_iter a
                  b
                  p*p + q*q
                  q*q + 2*p*q
                  n/2)
      :else
        (fib_iter (b*q + a*q + a*p)
                  (b*p + a*q)
                  p
                  q
                  n-1))
[1] http://arclanguage.org/item?id=16699