Skip to content

Instantly share code, notes, and snippets.

@tonymadbrain
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonymadbrain/bd62212fe731e1971cfa to your computer and use it in GitHub Desktop.
Save tonymadbrain/bd62212fe731e1971cfa to your computer and use it in GitHub Desktop.
total = 0
cur = 0
puts "Enter numbers separated by commas and press 'Enter'"
array = gets.chomp
puts "Enter X:"
X = gets.chomp
A = array.split(',')
n = A.length
A.each do |a|
total+=1 if a == X
end
if total == 0
puts "-1"
elsif n != total
os = n
for i in 0...n
os-=1
cur +=1 if A[i] == X
if os - (total-cur)==cur
answer = i+1
puts "Answer: #{answer}"
end
end
elsif n == total
puts "All the same"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment