Created
November 21, 2013 14:44
-
-
Save justuseapen/7582753 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
departures = | |
{"Train 1" => 2, | |
"Train 2" => 5, | |
"Train 3" => 7.5, | |
"Train 4" => 8.5, | |
"Train 5" => 9, | |
"Train 6" => 10, | |
"Train 7" => 11.5, | |
"Train 8" => 13.5, | |
"Train 9" => 14.5, | |
"Train 10" => 17, | |
"Train 11" => 18, | |
"Train 12" => 19, | |
"Train 13" => 24} | |
puts "What time are you leaving?" | |
time = gets.chomp.to_i | |
time_difference = 100 | |
next_train = "" | |
next_time = 0 | |
departures.each do |train,departure_time| | |
if time < departure_time | |
difference = departure_time - time | |
if time_difference > difference | |
time_difference = difference | |
next_train = train | |
next_time = departure_time | |
end | |
end | |
end | |
if next_train == "Train 13" | |
puts "Just a small town girl | |
Living in a lonely world, | |
she took #{next_train} going an-y-wherrrreeee!" | |
else | |
puts "The best train for you is #{next_train} which leaves at #{next_time}!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment