I have been learning ruby for the last few weeks and I came across something like:
array = [10, 20, 20];
# => 10
[10, 20, 20]
array.reduce(:^) performs the bitwise XOR of the elements of
array = [10, 20, 20], this performs
(10 ^ 20) ^ 20, giving the result
The bitwise XOR of a number and itself is 0 and XOR is associative (the order is not important). Every pair of identical numbers in the array is therefore cancelled out, leaving the XOR of any numbers that occur an odd number of times. If there is a single number in the array that occurs an odd number of times, then this number will be the result.