From f3e7b55492f4a72e2e7b7186f7a9fe3ad5a82470 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Sun, 7 Mar 2021 13:12:23 -0800 Subject: [PATCH] Update fibonacci.rb --- maths/fibonacci.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/maths/fibonacci.rb b/maths/fibonacci.rb index f2f77e4..4515de2 100644 --- a/maths/fibonacci.rb +++ b/maths/fibonacci.rb @@ -20,6 +20,7 @@ # Time complexity: O(1). Constant time complexity since we are using no loops or recursion # and the time is based on the result of performing the calculation using Binet's formula. +# # Space complexity: O(1). The space used is the space needed to create the variable # to store the golden ratio formula. @@ -29,16 +30,16 @@ def fibonacci(n) end n = 2 +puts(fibonacci(n)) # Output: 1 # Explanation: F(2) = F(1) + F(0) = 1 + 0 = 1. -puts(fibonacci(n)) n = 3 +puts(fibonacci(n)) # Output: 2 # Explanation: F(3) = F(2) + F(1) = 1 + 1 = 2. -puts(fibonacci(n)) n = 4 +puts(fibonacci(n)) # Output: 3 # Explanation: F(4) = F(3) + F(2) = 2 + 1 = 3. -puts(fibonacci(n))