Scripting competition

Sarah Reichelt sarah.reichelt at gmail.com
Mon May 11 22:43:43 EDT 2009


On Tue, May 12, 2009 at 11:17 AM, Brian Yennie <briany at qldlearning.com> wrote:
> 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

Thanks for this Brian, I have altered my on-rev page to use your
algorithm, so now I am officially disqualified :-)
<http://troz.on-rev.com/fib.irev>

Cheers,
Sarah



More information about the use-livecode mailing list