Scripting competition

Brian Yennie briany at qldlearning.com
Mon May 11 21:17:52 EDT 2009


Graciously submitted. I believe this will eventually fail, because it  
uses naive "carry the 1" logic, but seems to match up through fib(300)  
at least.

function fib n
   put 0 into thisNum
   put 1 into nextNum
   repeat n-1
      put 0 into tCarry
      put empty into tSum
      if (length(nextNum) > length(thisNum)) then put "0" before thisNum
      repeat with i=length(nextNum) down to 1
         get ((char i of thisNum) + (char i of nextNum) + tCarry)
         if (it <10) then
            put 0 into tCarry
            put it before tSum
         else
            put 1 into tCarry
            put (it - 10) before tSum
         end if
      end repeat
      if (tCarry= 1) then put "1" before tSum
      put nextNum into thisNum
      put tSum into nextNum
   end repeat
   return tSum
end fib




More information about the use-livecode mailing list