Skip to content

Instantly share code, notes, and snippets.

@abishekk92
Created May 18, 2012 13:38
Show Gist options
  • Save abishekk92/2725321 to your computer and use it in GitHub Desktop.
Save abishekk92/2725321 to your computer and use it in GitHub Desktop.
Solution to InterviewStreet Manipulative Numbers
print "Please enter the limits"
number_limit=gets
limit=number_limit.to_i
numbers=[]
xor=[]
def compute_k(foo)
count=0
foo=foo+1 if foo%2==0
until foo ==1
if foo%2==0
foo=foo/2
count=count+1
else
count=0
end
end
return count
end
unless limit > 100
until limit==0
numbers.push(gets)
limit=limit-1
end
end
for i in 0..numbers.length-1
for j in i+1..numbers.length
xor.push(numbers[i].to_i^numbers[j].to_i)
end
end
# value=min.sort[0]
#unless temp == 0
#else
# value+=1
#end
if(numbers.length<3)
k=compute_k(xor[0].to_i)
else if(numbers.length==3)
k=compute_k(xor[1].to_i)
else
k=compute_k(xor[numbers.length-3].to_i)
end
if k >=0
if k ==0
puts k+1
else
puts k
end
else
puts -1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment