For more information on Parity: Wikipedia
Challenge
Write a program that takes an input (stdin, argv, ect) of four nibbles and two parity nibbles. Your program should then test to see whether the 'block' is valid, using even parity; if it is then output 1
. Then try to make any corrections, if correction is possible output the corrected block. If you cannot correct the block output -1
. You can assume the parity nibbles are never corrupt.
To re-cap and clarify:
- If the input is valid output
1
. - If the input is invalid and fixable output the fixed block.
- If the input is invalid and cannot be fixed output
-1
. - You can only edit bits if their respective row and column in the parity bit is incorrect.
Input Format:
<NIBBLE> <NIBBLE> <NIBBLE> <NIBBLE> <PARITY-Y> <PARITY-X>
So 1010 0111 1101 1011 1011 0111
Would look like:
Winning
This is code-golf: Smallest program wins.
Input and Output Examples
Input 1010 0111 1101 1011 1011 0111
Output 1
The Input is Valid
Input 1010 0011 1101 1011 1011 0111
Output 1010 0111 1101 1011
The Input was Invalid, but correctable
Input 1010 0001 1101 1011 1011 0111
Output -1
The Input was Invalid, and not correctable
0000 0000
for example, in more than one way. You can also correct your example1011 0111
bits to nibbles0000 1011 1011 1011
, etc. I ask because you use the plural in "...try to make corrections..." \$\endgroup\$ – Geobits May 29 '14 at 0:26