Skip to content

Instantly share code, notes, and snippets.

@kyuden
Created July 8, 2013 14:04
Show Gist options
  • Save kyuden/5949073 to your computer and use it in GitHub Desktop.
Save kyuden/5949073 to your computer and use it in GitHub Desktop.
function call counts
class Fibona
@@n1, @@n2 = 0, 0
def self.fibonacci(n)
if n > 3
@@n2 += 1 if n == 4
return fibonacci(n - 2) + fibonacci(n - 1) + 1;
elsif n == 3
@@n2 += 1
@@n1 += 1
return 3;
elsif n == 2
return 1;
elsif n == 1
return 0;
end
end
def self.sum
[@@n1, @@n2]
end
end
p Fibona.fibonacci(20)
puts Fibona.sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment