Skip to content

Ports - Margaret#14

Open
msfinnan wants to merge 3 commits into
Ada-C11:masterfrom
msfinnan:master
Open

Ports - Margaret#14
msfinnan wants to merge 3 commits into
Ada-C11:masterfrom
msfinnan:master

Conversation

@msfinnan
Copy link
Copy Markdown

@msfinnan msfinnan commented Apr 9, 2019

No description provided.

Copy link
Copy Markdown

@mmcknett mmcknett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job! This solution looks great overall, minus some minor nits.

Checklist

  • Clean, working code
    • Works just fine!
    • The minor formatting issues and the variable naming are detracting from the cleanliness of this solution.
  • Efficient code - give feedback as you would give to a peer on your team
  • A detailed explanation of time and space complexity (explains what n stands for, explains why it would be a specific complexity, etc.)
    • Be sure to briefly explain your time and space complexity analyses.
  • All test cases for the assignment should be passing.

Comment thread lib/factorial.rb
# 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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this concise explanation for the space complexity. :)

Comment thread lib/factorial.rb

def factorial(number)
raise NotImplementedError
return 1 if number == 0
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] You should definitely indent all the lines between def factorial(number) and the final end for readability.

Comment thread lib/factorial.rb
end



Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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.

Comment thread lib/factorial.rb
raise ArgumentError, "Enter an integer"
end
a = 1
b = number
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 factorial(1) returns the right thing. In other cases I'd say it's duplicative to add && number == 1 to your return 1 if statement up at the top, but in this case I think it might actually benefit readability. Not something you need to change; I only note it to show you how unpredictable "readability" can be as a problem. Humans, am I right?

Comment thread lib/factorial.rb
a = 1
b = number
while a < number
b = b * (number - a)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a and b aren't particularly descriptive variable names. For b, I'd suggest calling it product -- you're using it to accumulate the overall product of every number between 1 and number. a is a little harder to name, but you could decrement number (i.e. do number -= 1 every loop) in order to not need a at all.

Comment thread lib/factorial.rb
# 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
Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants