Skip to content

Instantly share code, notes, and snippets.

@chinmaydd

chinmaydd/try.rb Secret

Last active August 29, 2015 14:10
Show Gist options
  • Save chinmaydd/bd44682ab0e66f22a5b2 to your computer and use it in GitHub Desktop.
Save chinmaydd/bd44682ab0e66f22a5b2 to your computer and use it in GitHub Desktop.
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