Skip to content

Instantly share code, notes, and snippets.

@tonymadbrain
Created February 2, 2015 10:33
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/1e9f4514b57357600719 to your computer and use it in GitHub Desktop.
Save tonymadbrain/1e9f4514b57357600719 to your computer and use it in GitHub Desktop.
def main(arr,x)
total = 0
cur = 0
arr = arr.split(',')
n = arr.length
arr.each do |a|
total+=1 if a == x
end
if total == 0
return -1
elsif n != total
os = n
for i in 0...n
os-=1
cur +=1 if arr[i] == x
if os - (total-cur)==cur
answer = i+1
puts "Answer: #{answer}"
end
end
elsif n == total
puts "All the same"
end
end
puts "Enter numbers separated by commas and press 'Enter'"
array = gets.chomp
puts "Enter X:"
x_gets = gets.chomp
main(array,x_gets)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment