Skip to content

Commit e7bc55c

Browse files
committed
fix: issue TheAlgorithms#9793
1 parent 6b47421 commit e7bc55c

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

Diff for: maths/base_neg2_conversion.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,14 @@ def decimal_to_negative_base_2(num: int) -> int:
2323
return 0
2424
ans = ""
2525
while num != 0:
26-
rem = num % -2
27-
num = num // -2
26+
num,rem =divmod(num, -2)
2827
if rem < 0:
2928
rem += 2
3029
num += 1
31-
3230
ans = str(rem) + ans
33-
3431
return int(ans)
3532

3633

3734
if __name__ == "__main__":
3835
import doctest
39-
40-
doctest.testmod()
36+
doctest.testmod()

0 commit comments

Comments
 (0)