Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the code is not working yet #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 68 additions & 2 deletions mbta.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,71 @@

# your solution here
def stops_between_stations

end
def one_line_stops(line, start_stop, end_stop)

lines = {
"red line" => ["South Station", "Park Street", "Kendall", "Central", "Harvard", "Porter", "Davis", "Alewife"],
"green line" => ["Government Center", "Park Street", "Boylston", "Arlington", "Copley", "Hynes", "Kenmore"],
"orange line" => ["North Station", "Haymarket", "Park Street", "State", "Downtown Crossing", "Chinatown", "Back Bay", "Forest Hills"]
}

stops_counter = 0

lineArray = lines[line]
station_name = ""

start_stop_index = lineArray.index start_stop
end_stop_index = lineArray.index end_stop

if (start_stop_index < end_stop_index)
i = start_stop_index + 1
while i <= end_stop_index do
station_name += lineArray[i]
stops_counter += 1
i +=1

end
return stops_counter}
else
i = start_stop_index - 1
while i >= end_stop_index do
station_name += lineArray[i]
stops_counter += 1
i -=1

end
return stops_counter
# return station_name
end



end

def stops_between_stations(start_line,start_stop,end_line, end_stop)
lines = {
"red line" => ["South Station", "Park Street", "Kendall", "Central", "Harvard", "Porter", "Davis", "Alewife"],
"green line" => ["Government Center", "Park Street", "Boylston", "Arlington", "Copley", "Hynes", "Kenmore"],
"orange line" => ["North Station", "Haymarket", "Park Street", "State", "Downtown Crossing", "Chinatown", "Back Bay", "Forest Hills"]
}
lineArray = lines[line]
station_name = ""

start_stop_index = lineArray.index start_stop
end_stop_index = lineArray.index end_stop
stops_counter = 0
station_name = ""

if start_line == end_line
trip = one_line_stops(start_line, start_stop,end_stop)
puts "your total stops are #{ trip } stops"
else
first_trip = one_line_stops(start_line, start_stop, "Park Street")
second_trip = one_line_stops(end_line, "Park Street", end_stop)
total_stops = first_trip + second_trip
puts "your total stops are #{ total_stops } stops"

end
end