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

This commit is contained in:
AJ ONeal 2012-07-18 10:09:01 -06:00
parent 0d9c949287
commit 2c450f1404
2 changed files with 53 additions and 0 deletions

32
fibonacci.lua Normal file
View File

@ -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 Normal file
View File

@ -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()