-
Notifications
You must be signed in to change notification settings - Fork 51
Spruce - Emily C #40
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?
Spruce - Emily C #40
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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "python.testing.pytestArgs": [ | ||
| "tests" | ||
| ], | ||
| "python.testing.unittestEnabled": false, | ||
| "python.testing.pytestEnabled": true | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,5 +6,25 @@ def newman_conway(num): | |
| """ Returns a list of the Newman Conway numbers for the given value. | ||
| Time Complexity: ? | ||
| Space Complexity: ? | ||
|
Comment on lines
7
to
8
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. 👀 Implementation looks good, but what are the time and space complexity for this approach? |
||
|
|
||
| P(n) = P(P(n - 1)) + P(n - P(n - 1)) | ||
| """ | ||
| pass | ||
| # base = ['1','1'] | ||
| if num == 0: | ||
| raise ValueError() | ||
|
Comment on lines
+13
to
+14
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. We should raise this error for any value below the valid starting point of the sequence: if num <= 0:
raise ValueError() |
||
| if num == 1: | ||
| return('1') | ||
| # for i in range(num): | ||
| # if i > 1: | ||
| # base.append(str(int(base[int(base[i - 1])]) + int(base[i - int(base[i - 1])]))) | ||
|
|
||
| # return ' '.join(base) | ||
|
|
||
| f = [0, 1, 1] | ||
|
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. ✨ Nice use of a buffer slot to account for the 1-based calculation. |
||
| r = 1 | ||
| # To store values of sequence in array | ||
| for i in range(3, num + 1): | ||
| r = f[f[i-1]]+f[i-f[i-1]] | ||
| f.append(r) | ||
|
|
||
| return ' '.join([str(j) for j in f[1:]]) | ||
|
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. ✨ Nice use of a list comprehension to convert the numeric values to strings. Another approach would be to use the return ' '.join(map(str, f[1:])) |
||
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.
👀 Implementation looks good, but what are the time and space complexity for this approach?
How would this compare to a "naïve" approach? Though this might not look like what we would think of as a dynamic programming approach, this article has a fairly good explanation of why it is. The main reason we look for dynamic programming approaches is to significantly improve the time complexity of an otherwise nasty algorithm.