Skip to content

Commit 2f15194

Browse files
Merge branch 'branch1' of github.com:AyushChakraborty/TheAlgorithms into branch1
2 parents ac9983e + 6817870 commit 2f15194

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

bit_manipulation/hamming_code_generator.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@ def hamming_15_11(number: str) -> str:
3939
4040
"""
4141
is_bin = True # assuming it's binary initially
42-
for i in number:
43-
if i not in ("0", "1"):
42+
for i in number:
43+
if i not in ("0", "1"):
4444
is_bin = False
4545
break
4646

4747
if len(number) == 11 and is_bin:
48-
4948
digits = [int(number[i]) for i in range(len(number))]
5049

5150
total_ones = sum(digits)
@@ -60,11 +59,11 @@ def hamming_15_11(number: str) -> str:
6059

6160
redundant_bits = [0] * 5
6261

63-
redundant_bits_index = 1
62+
redundant_bits_index = 1
6463
for positions in parity_positions.values():
6564
parity = 0
66-
for idx in positions:
67-
parity ^= digits[idx]
65+
for idx in positions:
66+
parity ^= digits[idx]
6867
redundant_bits[redundant_bits_index] = parity
6968
redundant_bits_index += 1
7069

@@ -76,8 +75,8 @@ def hamming_15_11(number: str) -> str:
7675
^ redundant_bits[4]
7776
)
7877

79-
j = -1
80-
r = 0
78+
j = -1
79+
r = 0
8180
redundant_bit_locations = [0, 1, 2, 4, 8]
8281
for k in range(16):
8382
if k in redundant_bit_locations:
@@ -92,6 +91,7 @@ def hamming_15_11(number: str) -> str:
9291
if len(number) != 11 or not is_bin:
9392
return "Input must be an 11-bit binary string containing only '0's and '1's."
9493

94+
9595
if __name__ == "__main__":
9696
import doctest
9797

0 commit comments

Comments
 (0)