Hi guys,
I am new to Ruby and try to learn it. I have problem that I am stuck with on one of the conditions. This is my code:
def check_trip(start, target, stations, station_links, result = "Impossible" )
station_links.each_pair do |key, value|
if value.include?(target)
return "Possible" if key == start #why return don't work?
result = check_trip(start, key, stations, station_links)
end
end
result
end
stations = ["ADL", "MEL", "SYD", "BRI"]
links = {"ADL" => ["MEL"], "MEL" => ["ADL", "SYD"], "SYD" => ["BRI"]}
links.default = []
check_trip( "ADL", "BRI", stations, links )
check_trip( "MEL", "BRI", stations, links )
check_trip( "SYD", "ADL", stations, links )
The first 2 conditions are returning OK but the last one gets in stuck level too deep. Sorry if this is a dumb question for you guys.
Thanks!