Skip to content

Instantly share code, notes, and snippets.

@jmoon90
Last active December 28, 2015 20:08
Show Gist options
  • Select an option

  • Save jmoon90/7554730 to your computer and use it in GitHub Desktop.

Select an option

Save jmoon90/7554730 to your computer and use it in GitHub Desktop.
alculate the user's next train based on their input of when the earliest is that they can leave. For ease of development, use a 24 hour format where 1:15PM == 13.25.
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. "
train_data = {
1 => 2,
2 => 5,
3 => 7.5,
4 => 8.5,
5 => 9,
6 => 10,
7 => 11.5,
8 => 13.5,
9 => 14.5,
10 => 17,
11 => 18,
12 => 19,
13 => 24
}
puts "When time leaving are you leaving?"
print "> "
leave_office = gets.chomp.to_f
train_to_catch = []
train_no = []
train_data.each do |key, values|
if leave_office <= values
train_to_catch << values
train_no << key
end
end
leave_train = train_to_catch.shift
puts "You should catch Train #{train_no.shift} leaving at #{leave_train}"
puts
puts song if leave_train == 24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment