Skip to content

Instantly share code, notes, and snippets.

@nazarov-yuriy
Last active March 27, 2016 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nazarov-yuriy/9cf0d7595daa6624d627 to your computer and use it in GitHub Desktop.
Save nazarov-yuriy/9cf0d7595daa6624d627 to your computer and use it in GitHub Desktop.
// 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