In message "Re: Fibonacci Number Generators"
on 02/04/06, "Christoph" <chr_news / gmx.net> writes:
|Fib = [0,1]
|
|def Fib.[](n)
| super || (
| for i in length..n do
| self[i] = super(i-1)+super(i-2)
| end
| super)
|end
That's good!
The following is a non-recursive version of **:
def **(n)
if n == 0
type.new(1, 0)
elsif n > 0
z = x = self
n -= 1
while (n & 1 != 0 and z *= x; (n >>= 1) != 0)
x = x * x
end
z
end
end
Shin-ichiro HARA