Skip to content

Instantly share code, notes, and snippets.

@zumbalogy
Last active December 30, 2015 08:59
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 zumbalogy/7806202 to your computer and use it in GitHub Desktop.
Save zumbalogy/7806202 to your computer and use it in GitHub Desktop.
No input validation, but yes to multi-stops
n = %w( Times_Square 34th 28th 23th Union_Square 8th )
l = %w( 8th 6th Union_Square 3rd 1st )
six = %w( Grand_Central 33rd 28th 23rd Union_Square Astor_Place )
q = %w( Times_Square Herald_Square Union_Square Canal_St )
puts "What train on? [n, l, six, q]"
on_train = gets.chomp
case on_train
when "n"
@on = n
when "l"
@on = l
when "six"
@on = six
when "q"
@on = q
end
puts "which stop? #{@on}"
on_stop = gets.chomp
puts "what train off?"
off_train = gets.chomp
case off_train
when "n"
@off = n
when "l"
@off = l
when "six"
@off = six
when "q"
@off = q
end
puts "which stop? #{@off}"
off_stop = gets.chomp
intersections = []
@on.each do |get_on|
@off.each do |get_off|
if get_on == get_off
intersections << get_off
end
end
end
if @on != @off
@lowest_distance = 1000
intersections.each do |intersect|
first_dis = (@on.index(intersect) - @on.index(on_stop)).abs
second_dis = (@off.index(intersect) - @off.index(off_stop)).abs
dis = first_dis + second_dis
if dis < @lowest_distance
@lowest_distance = dis
end
end
puts "your distance is #{@lowest_distance}"
else
dis = (@on.index(off_stop) - @on.index(on_stop)).abs
puts "your distace is #{dis}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment