8
Note: This is the radiation-hardening version of my previous challenge Pristine Bit Checking. This should be much more difficult than that one.
Write a program/function that takes two integers in the range \$0\$ to \$255\$ inclusive, and returns whether the binary forms of the numbers are exactly one bit different.
For example, \$1\$ and \$0\$ have binary forms 00000001
and 00000000
, which are one bit apart. Similarly, \$152\$ and \$24\$ are 010011000
and 000011000
, so they return true.
However, your code must be radiation-hardened, such that if any one bit in your program is flipped, it should still work correctly. For example, if your program was the single byte a
(01100001
), then all the 8 possible modified programs:
á ! A q i e c `
must still work correctly. Make sure you are modifying by bytes (e.g. the á
up there is actually representing the byte \$225\$, not the actual two byte character á
).
Test cases:
With Truthy meaning they are different by one bit.
0,1 => Truthy
1,0 => Truthy
152,24 => Truthy
10,10 => Falsey
10,11 => Truthy
11,12 => Falsey
255,0 => Falsey
Rules:
- Provide a testing framework that can verify that your program is properly radiation-hardened, since there will be a lot of possible programs (number of bytes*8), or else a complete proof of validity.
- Please make sure to double-check your program is valid before you post it.
- Output can to be either truthy/falsey (either way around is fine), or else as one distinct value for truthy and the rest as falsey
- This can be through any of the Standard input/output methods
Here is a helper program that can be used to produce all the variations of an inputted program.
4"should be much more difficult than that one" -- this is stating the matter lightly – Jonah – 2019-08-08T02:42:19.557
For the record, ignoring empty programs, this would be impossible in any language whose code must be valid UTF-8. – Ørjan Johansen – 2019-08-09T00:03:38.917