All problems
Hamming (7,4) Batch Encode
Problem
Encode a list of 4-bit data blocks with the systematic Hamming(7,4) code. For data [d1, d2, d3, d4] compute p1 = d1 ^ d2 ^ d4, p2 = d1 ^ d3 ^ d4, and p4 = d2 ^ d3 ^ d4, then emit the codeword [p1, p2, d1, p4, d2, d3, d4]. Return a list with one codeword per input block, and an empty list for empty input.
Hint
Each parity bit covers the data positions whose binary labels contain that parity bit.
Test cases
case 1
in: [[[1,0,1,1]]]
expected: [[0,1,1,0,0,1,1]]
case 2
in: [[[0,0,0,0],[1,1,1,1]]]
expected: [[0,0,0,0,0,0,0],[1,1,1,1,1,1,1]]
case 3
in: [[]]
expected: []
case 4
in: [[[1,0,0,0]]]
expected: [[1,1,1,0,0,0,0]]
Starter codePython
def hamming_74_batch_encode(blocks):
# Your code here
pass4 test cases · run your code against them in the editor