-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ports - Margaret #14
base: master
Are you sure you want to change the base?
Ports - Margaret #14
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,54 @@ | ||
# Computes factorial of the input number and returns it | ||
# Time complexity: ? | ||
# Space complexity: ? | ||
# Time complexity: Linear or O(n) where n is the number input | ||
# Space complexity: Constant or O(1), will have the same number of variables no matter the size of the input | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this concise explanation for the space complexity. :) |
||
|
||
def factorial(number) | ||
raise NotImplementedError | ||
return 1 if number == 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] You should definitely indent all the lines between |
||
if number == nil | ||
raise ArgumentError, "Enter an integer" | ||
end | ||
a = 1 | ||
b = number | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] I had to run the tests and stare at this to prove to myself that |
||
while a < number | ||
b = b * (number - a) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
a += 1 | ||
end | ||
return b | ||
end | ||
|
||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] It's good to get in the habit now of deleting lots of empty lines at the end of code files. You'll definitely get nit-picky feedback on these sorts of formatting things on the job. |
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also briefly explain why.