Skip to content

Instantly share code, notes, and snippets.

View jalkoby's full-sized avatar

Sergii Pchelintsev jalkoby

View GitHub Profile
@mvidaurre
mvidaurre / fibo_tail_recursion.rb
Created April 17, 2014 19:30
Calculate the nth Fibonacci number, f(n). Using invariants for https://github.com/RayHightower/fibonacci
# Calculate the nth Fibonacci number, f(n). Using invariants
def fibo_tr(n, acc1, acc2)
if n == 0
0
elsif n < 2
acc2
else
return fibo_tr(n - 1, acc2, acc2 + acc1)
end
end