All problems
Convolutional Encode Stream
Problem
Encode a whole bit stream with a rate-1/2 convolutional encoder. The state list holds the previous input bits, and for each new bit form combined = [bit] + state; each output parity is the XOR of the combined bits named by its tap list, after which the state shifts in the new bit. Return the flat interleaved stream [p1, p2, p1, p2, ...].
Hint
Tap index 0 is the current bit, so a tap list of [0] just copies the input to that output.
Test cases
case 1
in: [[1,0,1],[0,0],[0,1,2],[0,2]]
expected: [1,1,1,0,0,0]
case 2
in: [[1,1],[0,0],[0,1],[0,1,2]]
expected: [1,1,0,0]
case 3
in: [[],[0,0],[0,1],[0,1,2]]
expected: []
case 4
in: [[1,0,0,1],[0],[0,1],[0]]
expected: [1,1,1,0,0,0,1,1]
Starter codePython
def convolutional_encode(bits, state, taps1, taps2):
# Your code here
pass4 test cases · run your code against them in the editor