-
-
Save chinmaydd/bd44682ab0e66f22a5b2 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
n = gets.chomp.to_i | |
arr = [] | |
n.times do | |
temp = gets.chomp.to_i | |
arr.push temp | |
end | |
arr.sort! | |
arr.reverse! | |
sig = Math.log(arr[0], 2).to_i | |
t = 0 | |
while sig >= 1 | |
i = t | |
while i < n && (arr[i]&sig)==0 | |
i+=1 | |
end | |
if i>=n | |
next | |
end | |
arr[t],arr[i] = arr[i], arr[t] | |
for j in 0..n-1 | |
if j!=t && (arr[j]&sig!=0) | |
arr[j] = arr[j]^arr[t] | |
end | |
end | |
t+=1 | |
sig>>=1 | |
end | |
res = 0 | |
for k in 0..n-1 | |
res = res^arr[k] | |
end | |
puts res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment