-
Notifications
You must be signed in to change notification settings - Fork 47
Branches - Linnea #44
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,5 +4,47 @@ | |
| # Space Complexity - ? (should be O(n)) | ||
| # Hint, you may want a recursive helper method | ||
| def fibonacci(n) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Comment on lines
+24
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes! |
||
| return fibonacci_helper(n, s, current + 1) | ||
| end | ||
|
|
||
| #Iterative | ||
|
|
||
| # def fib(n) | ||
| # if n == 0 || n == 1 | ||
| # return n | ||
| # end | ||
| # solution = [0, 1] | ||
| # current = 2 | ||
| # while current < n | ||
| # p current | ||
| # p solution, "before" | ||
| # temp = solution[1] | ||
| # solution[1] = solution[0] + solution[1] | ||
| # solution[0] = temp | ||
| # # solut | ||
|
|
||
| # current += 1 | ||
| # p solution, "after" | ||
| # end | ||
| # return solution[0] + solution[1] | ||
| # end | ||
| 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(1) | ||
|
Comment on lines
+3
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The time/space complexity will be the same O(log10n) |
||
| def super_digit(n) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
|
||
| 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 | ||
| # def refined_super_digit(n, k) | ||
|
|
||
| # end | ||
|
|
||
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 answers here?