For more information on Parity: Wikipedia
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
- If the input is invalid and fixable output the fixed block.
- If the input is invalid and cannot be fixed output
- You can only edit bits if their respective row and column in the parity bit is incorrect.
<NIBBLE> <NIBBLE> <NIBBLE> <NIBBLE> <PARITY-Y> <PARITY-X>
1010 0111 1101 1011 1011 0111 Would look like:
This is code-golf: Smallest program wins.
Input and Output Examples
1010 0111 1101 1011 1011 0111
The Input is Valid
1010 0011 1101 1011 1011 0111
1010 0111 1101 1011
The Input was Invalid, but correctable
1010 0001 1101 1011 1011 0111
The Input was Invalid, and not correctable