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

Leaves - Cloudy #39

Open
wants to merge 2 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
16 changes: 13 additions & 3 deletions lib/fibonacci.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
# Improved Fibonacci

# Time Complexity - ?
# Space Complexity - ? (should be O(n))
# Time Complexity - O(n)
# Space Complexity - O(n)
# Hint, you may want a recursive helper method
def fibonacci(n)

if n in results
return results(n)
else
if n == 0
return 0
if n == 1
return 1
end
end
end
results[n] = fib(n-1) + fib(n-2)

Choose a reason for hiding this comment

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

Ok some serious issues here:

  1. There is no method called fib
  2. There is no object called results
  3. It looks like this is the bad 2n solution.

More to work on here. Take a look at the examples in the notes.

end
13 changes: 7 additions & 6 deletions lib/super_digit.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Superdigit

# Time Complexity - ?
# Space Complexity - ?
# Time Complexity - O(n)
# Space Complexity - O(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.

👍


return n if n < 10
ans = n % 10 + super_digit(n/10) # over 10
ans >= 10 ? super_digit(ans) : ans
end


# Time Complexity - ?
# Space Complexity - ?
def refined_super_digit(n, k)
#will come back too.
end