Skip to content
DeepForgeby svx
All problems
EasyInformation Theoryinfo-309

XOR Parity Recover

Problem

A set of integers is protected by a single XOR parity symbol equal to the XOR of the complete set. Given every symbol except one plus the parity, recover the missing symbol as parity ^ XOR(data), since XOR is its own inverse. Return the parity itself when data is empty.

Hint

XOR-ing the known values and the parity cancels every known symbol.

Test cases

case 1
in: [[1,2,3],4]
expected: 4
case 2
in: [[5,10],8]
expected: 7
case 3
in: [[],7]
expected: 7
case 4
in: [[9,9,9],9]
expected: 0
Starter codePython
def xor_parity_recover(data, parity):
    # Your code here
    pass

4 test cases · run your code against them in the editor