Created
February 2, 2015 10:33
-
-
Save tonymadbrain/1e9f4514b57357600719 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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