Last active
December 28, 2015 19:59
-
-
Save faizaanshamsi/7554419 to your computer and use it in GitHub Desktop.
Program will suggest next train based on departure time. If a train leaves exactly at departure time it will be suggested. If suggestion is before or after train times it will tell you there's no train available.
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
song = "***DON'T STOP...BELIEVIN'!*** | |
Just a small town girl | |
Living in a lonely world | |
She took the midnight train going anywhere | |
Just a city boy | |
Born and raised in South Detroit | |
He took the midnight train going anywhere | |
A singer in a smoky room | |
A smell of wine and cheap perfume | |
For a smile they can share the night | |
It goes on and on and on and on | |
Strangers waiting, up and down the boulevard | |
Their shadows searching in the night | |
Streetlights people, living just to find emotion | |
Hiding, somewhere in the night. " | |
times = { | |
"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, | |
} | |
best_option = 0 | |
best_time = 0 | |
output = true | |
reversed_times = times.invert | |
puts "What time are you leaving?" | |
leaving = gets.chomp.to_f | |
reversed_times.each do |time, train| | |
if leaving > 24 || leaving < 2 | |
output = false | |
break | |
end | |
(best_option = train) && (best_time = time) if leaving >= time | |
end | |
if output | |
puts "You should take #{best_option} leaving at #{best_time}" | |
puts song if best_option == reversed_times[24] | |
else | |
puts "There's no train at that time!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment