-
Notifications
You must be signed in to change notification settings - Fork 48
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
Leaves - Sabrina #31
base: master
Are you sure you want to change the base?
Leaves - Sabrina #31
Conversation
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.
Overall nice work, you hit the learning goals here. Well done.
lib/super_digit.rb
Outdated
def super_digit(n) | ||
|
||
puts "super_digit("+n.to_s+")" |
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.
I suggest leaving these out when you submit an answer.
puts "super_digit("+n.to_s+")" |
lib/super_digit.rb
Outdated
else | ||
sum = 0 | ||
while ((n / 10.0) > 0) | ||
puts " while" |
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.
puts " while" |
return new_solution | ||
end | ||
|
||
solutions = [last_solution, new_solution] |
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.
👍
# Time Complexity - O(n) | ||
# because the while loop to create the concatenated number | ||
# and the while loop adding the digits of the number are not nested. | ||
# Space Complexity - O(log k * n) | ||
def refined_super_digit(n, k) |
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.
This is the brute-force solution here. Can you think of a better way to do this with dynamic programming?
# Time Complexity - O(n) | ||
# Space Complexity - O(n) | ||
# you only keep the last two solutions, so the solutions array does not grow, | ||
# but you're still effectiving the stack by adding recursive calls | ||
# Hint, you may want a recursive helper method | ||
def fibonacci(n) |
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.
👍
No description provided.