-
Notifications
You must be signed in to change notification settings - Fork 29
Amy P #18
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?
Amy P #18
Conversation
CheezItMan
left a comment
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.
Nice work, you fully applied dynamic programming to these solutions. Well done!
| ## Wave 1 Newman-Conway Sequence | ||
|
|
||
| [Newman-Conway sequence](https://archive.lib.msu.edu/crcmath/math/math/n/n078.htm) is the one which generates the following integer sequence. 1 1 2 2 3 4 4 4 5 6 7 7….. and follows below recursive formula. | ||
| [Newman-Conway sequence](https://archive.lib.msu.edu/crcmath/math/math/n/n078.htm) is the one which generates the following integer sequence. 1 1 2 2 3 4 4 4 5 6 7 7….. and follows the below recursive formula. |
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.
😃
| # Space Complexity: ? | ||
| # Time complexity: O(n) where n is the size of the input | ||
| # Space Complexity: O(n) where n is the size of the input (space needed for storing each char) | ||
| def newman_conway(num) |
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.
👍
| result = [] | ||
| num.times do |i| | ||
| if i < 2 | ||
| result << 1 | ||
| else | ||
| last_char = result[i - 1] | ||
| result[i] = result[last_char - 1] + result[i - last_char] | ||
| end | ||
| end | ||
| return result.join(" ") |
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.
Very elegant solution!
No description provided.