Skip to content

Update doctests for power_sum.py #10288

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

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions backtracking/power_sum.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
The only solution is 2^2+3^2. Constraints: 1<=X<=1000, 2<=N<=10.
"""

from math import pow


def backtrack(
needed_sum: int,
Expand All @@ -23,15 +21,17 @@ def backtrack(
(0, 3)
>>> backtrack(100, 3, 1, 0, 0)
(0, 1)
>>> backtrack(800, 2, 1, 0, 0)
(0, 561)
>>> backtrack(500, 2, 1, 0, 0)
(0, 109)
>>> backtrack(1000, 10, 1, 0, 0)
(0, 0)
>>> backtrack(400, 2, 1, 0, 0)
(0, 55)
>>> backtrack(50, 1, 1, 0, 0)
(0, 3658)
"""
from math import pow

if current_sum == needed_sum:
# If the sum of the powers is equal to needed_sum, then we have a solution.
solutions_count += 1
Expand Down Expand Up @@ -61,8 +61,8 @@ def solve(needed_sum: int, power: int) -> int:
3
>>> solve(100, 3)
1
>>> solve(800, 2)
561
>>> solve(500, 2)
109
>>> solve(1000, 10)
0
>>> solve(400, 2)
Expand Down