News for hackers. Stuff that matters.
Re:That XOR Trick (2020) by j-pb on Monday January 18, 2021 @09:33AM (#25822134)
Ah off by one errors are hard:

> 1 ^ 2 ^ ... ^ n ^ A[0] ^ A[1] ^ ... ^ A[n - 1]

should be

> 1 ^ 2 ^ ... ^ n ^ A[0] ^ A[1] ^ ... ^ A[n - 2]

Because a 0 indexed array of length n-1, has n-2 as it's last index. After all, it's missing a value.

Re:That XOR Trick (2020) by epsilon-greedy on Monday January 18, 2021 @02:46PM (#25825753)
Author here (Florian): I just fixed this. Very good catch. Off-by-one errors are hard indeed. :)
Re:That XOR Trick (2020) by ml_giant on Monday January 18, 2021 @09:49AM (#25822278)
Let's try an example with n=4:

1 ^ 2 ^ 3 ^ 4 ^ A[0] ^ A[1] ^ A[2] ^ A[3]

It might be early in the morning and I am missing something, but it has n-1 as its last index. Any insight is appreciated :)

Edit: There is a missing number in the array, thus its last index is n-2. Thanks for the correction, OP.

Re:That XOR Trick (2020) by j-pb on Monday January 18, 2021 @09:56AM (#25822343)
Premise: A is containing all values in range [1, 4] except one:

Let's say that, without loss of generality:

> 1 ^ 2 ^ 3 ^ 4 ^ A[0]=1 ^ A[1]=2 ^ A[2]=3 ^ A[3]=4

However, A is now missing no value. Contradiction.

∎

Re:That XOR Trick (2020) by bonzini on Monday January 18, 2021 @09:52AM (#25822310)
But there are only 3 items in the array (for example 1, 2 and 4). So the last valid index is 2.
Re:That XOR Trick (2020) by ml_giant on Monday January 18, 2021 @09:53AM (#25822326)
Ah. I was about to make an edit to my comment as you are correct :) Thanks!