Permalink
Browse files

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

  • Loading branch information...
1 parent 0d9c949 commit 2c450f1404c76f97563151b2a4dd8da77a4ccc69 @coolaj86 committed Jul 18, 2012
Showing with 53 additions and 0 deletions.
  1. +32 −0 fibonacci.lua
  2. +21 −0 fibonacci.rb
View
@@ -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)
View
@@ -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()

0 comments on commit 2c450f1

Please sign in to comment.