Last active
March 27, 2016 11:36
-
-
Save nazarov-yuriy/9cf0d7595daa6624d627 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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