Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// https://habrahabr.ru/post/280192/
class OddPair {
static int[] getPair(List<Integer> data) {
int[][] x = [new int[32], new int[32]]
data.each { (0..31).each { i -> x[it>>i & 1][i] ^= it; } }
return [(0..31).findAll { x[0][it] != 0 && x[1][it] != 0 }, 0].flatten().collect({ [x[0][it], x[1][it]] })[0];
}
public static void main(String[] args) {
println getPair([0, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6 ])
println getPair([0, 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7])
println getPair([0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 5, 6, 7])
println getPair([0, 3, 5, 5])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment