Open the context
Choose the project folder and name the files or behavior involved.
Decode a seven-bit Hamming word under an explicit assumption of at most one flipped bit. Check intact words and every single-bit position, reject malformed or non-binary input and make no claim to detect multiple errors.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
def correct_hamming(word):
word = list(word)
if len(word) != 7 or any(type(b) is not int or b not in (0, 1) for b in word):
raise ValueError("hamming.word")
syndrome = 0
for parity in (1, 2, 4):
value = 0
for position in range(1, 8):
if position & parity:
value ^= word[position-1]
if value:
syndrome |= parity
if syndrome:
word[syndrome-1] ^= 1
data = (word[2] << 3) | (word[4] << 2) | (word[5] << 1) | word[6]
return data, syndromeThe example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.