Skip to content

Commit 501a1cf

Browse files
Remove unnecessary else statement (#7759)
* Remove unnecessary else statement * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 71e8ed8 commit 501a1cf

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

maths/karatsuba.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ def karatsuba(a, b):
1010
"""
1111
if len(str(a)) == 1 or len(str(b)) == 1:
1212
return a * b
13-
else:
14-
m1 = max(len(str(a)), len(str(b)))
15-
m2 = m1 // 2
1613

17-
a1, a2 = divmod(a, 10**m2)
18-
b1, b2 = divmod(b, 10**m2)
14+
m1 = max(len(str(a)), len(str(b)))
15+
m2 = m1 // 2
1916

20-
x = karatsuba(a2, b2)
21-
y = karatsuba((a1 + a2), (b1 + b2))
22-
z = karatsuba(a1, b1)
17+
a1, a2 = divmod(a, 10**m2)
18+
b1, b2 = divmod(b, 10**m2)
2319

24-
return (z * 10 ** (2 * m2)) + ((y - z - x) * 10 ** (m2)) + (x)
20+
x = karatsuba(a2, b2)
21+
y = karatsuba((a1 + a2), (b1 + b2))
22+
z = karatsuba(a1, b1)
23+
24+
return (z * 10 ** (2 * m2)) + ((y - z - x) * 10 ** (m2)) + (x)
2525

2626

2727
def main():

0 commit comments

Comments
 (0)