Skip to content

Commit 257a3ed

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 264e0e8 commit 257a3ed

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

quantum/shors_algorithm.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,7 @@ def shors_algorithm(n: int, max_attempts: int = 10) -> tuple[int, int] | None:
316316
raise ValueError("n is prime and cannot be factored")
317317

318318
# Check if n is a perfect power
319-
perfect_power = is_perfect_power(n)
320-
if perfect_power is not None:
319+
if (perfect_power := is_perfect_power(n)) is not None:
321320
base, _ = perfect_power
322321
return (base, n // base)
323322

@@ -457,9 +456,7 @@ def factor_with_explanation(n: int) -> None:
457456
print("Step 2: Quantum period finding (simulated)")
458457
print(" - Selecting random base a...")
459458

460-
factors = shors_algorithm(n)
461-
462-
if factors:
459+
if factors := shors_algorithm(n):
463460
print(" - Found suitable parameters")
464461
print()
465462
print("Step 3: Factor extraction")

0 commit comments

Comments
 (0)