Skip to content

Updated test cases of power_sum.py #9978

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

Merged
39 changes: 20 additions & 19 deletions backtracking/power_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ def backtrack(
"""
>>> backtrack(13, 2, 1, 0, 0)
(0, 1)
>>> backtrack(100, 2, 1, 0, 0)
(0, 3)
>>> backtrack(100, 3, 1, 0, 0)
>>> backtrack(10, 2, 1, 0, 0)
(0, 1)
>>> backtrack(800, 2, 1, 0, 0)
(0, 561)
>>> backtrack(1000, 10, 1, 0, 0)
>>> backtrack(10, 3, 1, 0, 0)
(0, 0)
>>> backtrack(400, 2, 1, 0, 0)
(0, 55)
>>> backtrack(50, 1, 1, 0, 0)
(0, 3658)
>>> backtrack(20, 2, 1, 0, 0)
(0, 1)
>>> backtrack(15, 10, 1, 0, 0)
(0, 0)
>>> backtrack(16, 2, 1, 0, 0)
(0, 1)
>>> backtrack(20, 1, 1, 0, 0)
(0, 64)
"""
if current_sum == needed_sum:
# If the sum of the powers is equal to needed_sum, then we have a solution.
Expand All @@ -57,17 +57,17 @@ def solve(needed_sum: int, power: int) -> int:
"""
>>> solve(13, 2)
1
>>> solve(100, 2)
3
>>> solve(100, 3)
>>> solve(10, 2)
1
>>> solve(800, 2)
561
>>> solve(1000, 10)
>>> solve(10, 3)
0
>>> solve(400, 2)
55
>>> solve(50, 1)
>>> solve(20, 2)
1
>>> solve(15, 10)
0
>>> solve(16, 2)
1
>>> solve(20, 1)
Traceback (most recent call last):
...
ValueError: Invalid input
Expand All @@ -90,4 +90,5 @@ def solve(needed_sum: int, power: int) -> int:
if __name__ == "__main__":
import doctest

# print(backtrack(80, 1, 1, 0, 0))
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you plan to keep this line of code?

doctest.testmod()