-
Notifications
You must be signed in to change notification settings - Fork 77
Danielle_Marcos #14
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
Danielle_Marcos #14
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,40 @@ | ||
| def ack (m, n): | ||
| """Return a value based on the Ackermann-Peter function.""" | ||
|
|
||
| if m == 0: | ||
| return n + 1 | ||
| elif m > 0 and n == 0: | ||
| return ack(m-1, 1) | ||
| elif m > 0 and n > 0: | ||
| return ack(m-1, ack(m, n-1)) | ||
| elif m < 0 and n < 0: | ||
| return None | ||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
| assert ack(0,0) == 1 | ||
| assert ack(0,1) == 2 | ||
| assert ack(0,2) == 3 | ||
| assert ack(0,3) == 4 | ||
| assert ack(0,4) == 5 | ||
|
|
||
| assert ack(1,0) == 2 | ||
| assert ack(1,1) == 3 | ||
| assert ack(1,2) == 4 | ||
| assert ack(1,3) == 5 | ||
| assert ack(1,4) == 6 | ||
|
|
||
| assert ack(2,0) == 3 | ||
| assert ack(2,1) == 5 | ||
| assert ack(2,2) == 7 | ||
| assert ack(2,3) == 9 | ||
| assert ack(2,4) == 11 | ||
|
|
||
| assert ack(3,0) == 5 | ||
| assert ack(3,1) == 13 | ||
| assert ack(3,2) == 29 | ||
| assert ack(3,3) == 61 | ||
| assert ack(3,4) == 125 | ||
|
|
||
| print"" | ||
| print "All Tests Pass" | ||
|
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. good idea to test the n, m < 0 cases, too. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| def fibonacci(n): | ||
| """Return the n value based on the Fibonacci series.""" | ||
| if n <= 0: | ||
| return 0 | ||
| elif n == 1: | ||
| return 1 | ||
| else: | ||
| return fibonacci(n-1) + fibonacci(n-2) | ||
|
|
||
| def lucas(n): | ||
| """Return the n value in the Lucas Numbers.""" | ||
| if n <= 0: | ||
| return 2 | ||
| elif n == 1: | ||
| return 1 | ||
| else: | ||
| return lucas(n-1) + lucas(n-2) | ||
|
|
||
| def sum_series(n, x=0, y=1): | ||
| if n <= 0: | ||
| return x | ||
|
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. what do you want for n < 0? Is it defined? |
||
| elif n == 1: | ||
| return y | ||
| else: | ||
| return sum_series(n-1, x, y) + sum_series(n-2, x, y) | ||
|
|
||
| if __name__ == "__main__": | ||
| """Validate that when an nth values are passed different positions are returned""" | ||
|
|
||
| # Validate Fibonacci tests pass successfully. | ||
| assert fibonacci(0) == 0 | ||
| assert fibonacci(1) == 1 | ||
| assert fibonacci(2) == 1 | ||
| assert fibonacci(3) == 2 | ||
| assert fibonacci(4) == 3 | ||
| assert fibonacci(5) == 5 | ||
| assert fibonacci(6) == 8 | ||
| assert fibonacci(7) == 13 | ||
|
|
||
| # Validate Lucas tests pass successfully. | ||
|
|
||
| assert lucas(0) == 2 | ||
| assert lucas(1) == 1 | ||
| assert lucas(2) == 3 | ||
| assert lucas(3) == 4 | ||
| assert lucas(4) == 7 | ||
| assert lucas(5) == 11 | ||
| assert lucas(6) == 18 | ||
| assert lucas(7) == 29 | ||
|
|
||
| # Validate sum_series tests for Fibonacci pass successfully. | ||
|
|
||
| assert sum_series(0) == 0 | ||
| assert sum_series(1) == 1 | ||
| assert sum_series(2) == 1 | ||
| assert sum_series(3) == 2 | ||
| assert sum_series(4) == 3 | ||
| assert sum_series(5) == 5 | ||
| assert sum_series(6) == 8 | ||
| assert sum_series(7) == 13 | ||
|
|
||
| # Validate sum_series tests for Lucas pass successfully. | ||
|
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. oops, looks like you forgot to update test for Lucas! |
||
|
|
||
| assert sum_series(0) == 0 | ||
| assert sum_series(1) == 1 | ||
| assert sum_series(2) == 1 | ||
| assert sum_series(3) == 2 | ||
| assert sum_series(4) == 3 | ||
| assert sum_series(5) == 5 | ||
| assert sum_series(6) == 8 | ||
| assert sum_series(7) == 13 | ||
|
|
||
| print "" | ||
| print "All Tests Pass" | ||
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.
what will happen if n < 0 and m == 0?
and what about m < 0, n > 0?
But otherwise, looks good.