Skip to main content
added 232 characters in body
Source Link
xnor
  • 149.7k
  • 26
  • 287
  • 676

Python 2, 35 bytes

lambda a,b:(a^b)&-(a^b)in[a^b or[]] 

Try it online!

Uses the power-of-two check n&-n==n, eliminating the n==0 false positive.

For reference, these are the pairs of one-char binary operators that are one bit apart, making them hard to use:

+ / - / * + % - < | < > 

Fortunately, & and ^ are not among these.

Also note that == can become <=, and + can become the comment character #.


Python 2, 41 bytes

lambda a,b:bin(a^b).count(`+True`)is+True 

Try it online!

Taking TFeld's lambda a,b:bin(a^b).count('1')==1 and making it pristine by changing the 1's to +True and == to is. Thanks to Jo King for 1 byte.

Python 2, 35 bytes

lambda a,b:(a^b)&-(a^b)in[a^b or[]] 

Try it online!

Uses the power-of-two check n&-n==n, eliminating the n==0 false positive.


Python 2, 41 bytes

lambda a,b:bin(a^b).count(`+True`)is+True 

Try it online!

Taking TFeld's lambda a,b:bin(a^b).count('1')==1 and making it pristine by changing the 1's to +True and == to is. Thanks to Jo King for 1 byte.

Python 2, 35 bytes

lambda a,b:(a^b)&-(a^b)in[a^b or[]] 

Try it online!

Uses the power-of-two check n&-n==n, eliminating the n==0 false positive.

For reference, these are the pairs of one-char binary operators that are one bit apart, making them hard to use:

+ / - / * + % - < | < > 

Fortunately, & and ^ are not among these.

Also note that == can become <=, and + can become the comment character #.


Python 2, 41 bytes

lambda a,b:bin(a^b).count(`+True`)is+True 

Try it online!

Taking TFeld's lambda a,b:bin(a^b).count('1')==1 and making it pristine by changing the 1's to +True and == to is. Thanks to Jo King for 1 byte.

added 770 characters in body
Source Link
xnor
  • 149.7k
  • 26
  • 287
  • 676

Python 2, 35 bytes

lambda a,b:(a^b)&-(a^b)in[a^b or[]] 

Try it online!

Uses the power-of-two check n&-n==n, eliminating the n==0 false positive.


Python 2, 41 bytes

lambda a,b:bin(a^b).count(`+True`)is+True 

Try it online!

Taking TFeld's lambda a,b:bin(a^b).count('1')==1 and making it pristine by changing the 1's to +True and == to is. Thanks to Jo King for 1 byte.

Python 2, 41 bytes

lambda a,b:bin(a^b).count(`+True`)is+True 

Try it online!

Taking TFeld's lambda a,b:bin(a^b).count('1')==1 and making it pristine by changing the 1's to +True and == to is. Thanks to Jo King for 1 byte.

Python 2, 35 bytes

lambda a,b:(a^b)&-(a^b)in[a^b or[]] 

Try it online!

Uses the power-of-two check n&-n==n, eliminating the n==0 false positive.


Python 2, 41 bytes

lambda a,b:bin(a^b).count(`+True`)is+True 

Try it online!

Taking TFeld's lambda a,b:bin(a^b).count('1')==1 and making it pristine by changing the 1's to +True and == to is. Thanks to Jo King for 1 byte.

added 17 characters in body
Source Link
xnor
  • 149.7k
  • 26
  • 287
  • 676

Python 2, 41 bytes

lambda a,b:bin(a^b).count(`+True`)is+True 

Try it online!

Taking TFeld's lambda a,b:bin(a^b).count('1')==1 and making it pristine by changing the 1's to +True and == to is. Thanks to Jo King for 1 byte.

Python 2, 41 bytes

lambda a,b:bin(a^b).count(`+True`)is+True 

Try it online!

Taking TFeld's lambda a,b:bin(a^b).count('1')==1 by changing the 1's to +True. Thanks to Jo King for 1 byte.

Python 2, 41 bytes

lambda a,b:bin(a^b).count(`+True`)is+True 

Try it online!

Taking TFeld's lambda a,b:bin(a^b).count('1')==1 and making it pristine by changing the 1's to +True and == to is. Thanks to Jo King for 1 byte.

deleted 13 characters in body
Source Link
xnor
  • 149.7k
  • 26
  • 287
  • 676
Loading
Source Link
xnor
  • 149.7k
  • 26
  • 287
  • 676
Loading