diff --git a/fibonacci.lua b/fibonacci.lua new file mode 100644 index 0000000..343688a --- /dev/null +++ b/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) diff --git a/fibonacci.rb b/fibonacci.rb new file mode 100644 index 0000000..6dce3a1 --- /dev/null +++ b/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()