Browse Source

I got a fever that can only be cured by... more fibonacci

master
AJ ONeal 12 years ago
parent
commit
2c450f1404
  1. 32
      fibonacci.lua
  2. 21
      fibonacci.rb

32
fibonacci.lua

@ -0,0 +1,32 @@
--[[
-- Good 'ol fashioned recursion
--]]
function fib (a, b)
print(a)
if b >= 100 then
print(b)
else
fib(b, a + b)
end
end
--[[
-- Good 'ol fashioned loop
--]]
function fibLoop()
local a = 1
local b = 1
repeat
print(a)
b = a + b
a = b - a
until b >= 100
print(a)
print(b)
end
--
fibLoop()
--fib(1, 1)

21
fibonacci.rb

@ -0,0 +1,21 @@
def fib1 a, b
puts a
return if (a >= 100)
fib1(b, a + b)
end
def fib2
a = 0
b = 1
while a <= 100
puts a
newb = a + b
a = b
b = newb
end
puts a
end
fib1 0, 1
puts ''
fib2()
Loading…
Cancel
Save