Skip to content

Instantly share code, notes, and snippets.

@kklimuk
Last active April 8, 2017 20:35
Show Gist options
  • Save kklimuk/6035b9f11be452b95646f573db37be21 to your computer and use it in GitHub Desktop.
Save kklimuk/6035b9f11be452b95646f573db37be21 to your computer and use it in GitHub Desktop.
class FibonacciCalculator
include RubyMemoized
def calculate(n)
return n if (0..1).include?(n)
calculate(n - 1) + calculate(n - 2)
end
memoized
def memoized_calculate(n)
return n if (0..1).include?(n)
memoized_calculate(n - 1) + memoized_calculate(n - 2)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment