Skip to content

Instantly share code, notes, and snippets.

@chinmaydd

chinmaydd/try.rb Secret

Created December 8, 2014 17:08
Show Gist options
  • Save chinmaydd/f82ad5fe3f088b1ff22c to your computer and use it in GitHub Desktop.
Save chinmaydd/f82ad5fe3f088b1ff22c to your computer and use it in GitHub Desktop.
n = gets.chomp.to_i
v = []
n.times do
temp = gets.chomp.to_i
v.push temp
end
v.sort!
v.reverse!
sig = 1
while sig <= v[0]
sig<<=1;
end
sig>>=1;
t = 0
while sig >= 1
i = t
while (i<n) && (v[i]&sig)==0
i+=1
end
if i>=n
sig>>=1
next
end
v[t],v[i] = v[i], v[t]
j = 0
while j < n
if j!=t && (v[j]&sig)!=0
v[j] = v[j]^v[t]
end
j+=1
end
t+=1
sig>>=1
end
res = 0
q = 0
while q < n
res = res^v[q]
q+=1
end
print res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment