Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

SBCL on my AMD FX(tm)-8350 Eight-Core Processor:

   ~$ sbcl
   This is SBCL 1.4.11, an implementation of ANSI Common Lisp.
   More information about SBCL is available at <http://www.sbcl.org/>.

   SBCL is free software, provided as is, with absolutely no warranty.
   It is mostly in the public domain; some portions are provided under
   BSD-style licenses.  See the CREDITS and COPYING files in the
   distribution for more information.
   * (defun fibonacci-tail-recursive ( n &optional (a 1) (b 1))
           (declare (optimize (speed 3) (safety 0) (debug 0))
                    (type fixnum n a b))
           (if (< n 1)
               a
               (fibonacci-tail-recursive (- n 1) b (+ a b))))

   FIBONACCI-TAIL-RECURSIVE
   * (time (fibonacci-tail-recursive 46))

   Evaluation took:
     0.000 seconds of real time
     0.000001 seconds of total run time (0.000001 user, 0.000000 system)
     100.00% CPU
     2,513 processor cycles
     0 bytes consed
  
     2971215073
   *


Different machine and superior algorithm, where are you aiming with this?


It's true, I only read recursive Fibonacci. Now I see my mistake.


That being said, this one [0] gives correct results and runs slightly faster :)

[0] https://gist.github.com/codr4life/59f2c02403b27d551e706f673b...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: