From 74ba579528f76b600a210eab39dbf1da8210fe59 Mon Sep 17 00:00:00 2001 From: Faiza Husain Date: Wed, 10 Apr 2019 18:55:46 -0700 Subject: [PATCH 1/2] Completed factorial --- lib/factorial.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/factorial.rb b/lib/factorial.rb index 6a4a408..6b245eb 100644 --- a/lib/factorial.rb +++ b/lib/factorial.rb @@ -2,5 +2,17 @@ # Time complexity: ? # Space complexity: ? def factorial(number) - raise NotImplementedError + # raise NotImplementedError + if number == nil + raise ArgumentError + end + + i = 1 + while number > 0 + i = number * i + number -= 1 + # i += 1 + end + + return i end From d07f59464587b7d1d3a8b92fc9a3b82c761a8101 Mon Sep 17 00:00:00 2001 From: Faiza Husain Date: Thu, 11 Apr 2019 10:59:00 -0700 Subject: [PATCH 2/2] Added space/time complexity --- lib/factorial.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/factorial.rb b/lib/factorial.rb index 6b245eb..032f939 100644 --- a/lib/factorial.rb +++ b/lib/factorial.rb @@ -1,6 +1,6 @@ # Computes factorial of the input number and returns it -# Time complexity: ? -# Space complexity: ? +# Time complexity: O(n) where n is the number +# Space complexity: O(1) def factorial(number) # raise NotImplementedError if number == nil