Skip to content
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

Yasmin- Leaves #45

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/fibonacci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
# Space Complexity - ? (should be O(n))
# Hint, you may want a recursive helper method
def fibonacci(n)

Choose a reason for hiding this comment

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

Take another look at the notes on fibonacci, there's more than enough there to make a stab at this problem.



end
28 changes: 23 additions & 5 deletions lib/super_digit.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
# Superdigit

# Time Complexity - ?
# Space Complexity - ?
# Time Complexity - o(n)
# Space Complexity - o(1)
Comment on lines +3 to +4

Choose a reason for hiding this comment

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

The time/space complexity will be O(log10 n)

def super_digit(n)

Choose a reason for hiding this comment

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

👍


new_num = 0
numbers = n.to_s.split("")
if numbers.length <= 1
return n
end
numbers.each do |i|
new_num += i.to_i
end
return super_digit(new_num)
end


# Time Complexity - ?
# Space Complexity - ?
def refined_super_digit(n, k)

Choose a reason for hiding this comment

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

👍


new_num = 0
times = k
numbers = n.to_s.split("")
if numbers.length <= 1
return n
end
numbers.each do |i|
new_num += i.to_i
end
new_n = times * new_num
return super_digit(new_n)
end

2 changes: 1 addition & 1 deletion test/fibonacci_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require_relative "test_helper"

describe "Fibonacci" do
xdescribe "Fibonacci" do
it "will raise an error for n < 0" do
expect {
# Act
Expand Down
2 changes: 1 addition & 1 deletion test/super_digit_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require_relative "test_helper"

xdescribe "super_digit" do
describe "super_digit" do
it "will return 2 for super_digit(9875)" do
# Act
answer = super_digit(9875)
Expand Down