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

Steph-Branches #36

Open
wants to merge 1 commit 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
19 changes: 18 additions & 1 deletion lib/fibonacci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,22 @@
# 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.

👍


return fibonacci_helper(n, solution = [0,1], current = 2)
end

def fibonacci_helper(n, s, current)
if n < 0
raise ArgumentError
end
if n == 0 || n == 1
return n
end
if current == n
return s[0] + s[1]
end
temp = s[1]
s[1] = s[0] + s[1]
s[0] = temp
return fibonacci_helper(n, s, current + 1)
Comment on lines +20 to +23

Choose a reason for hiding this comment

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

Yes!

end

7 changes: 6 additions & 1 deletion lib/super_digit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
# Time Complexity - ?
# Space Complexity - ?
def super_digit(n)

Choose a reason for hiding this comment

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

👍


if n < 0
return argumentError
end
return n if n.to_s.length == 1
return super_digit(n.digits.sum)
end


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


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