Rahul lives in City A and would like to travel to City B for work. There is a shuttle service for people in these cities which has a fixed schedule. The schedule for City A is a list of boarding times(at City A) and departure times(from City A) for each bus.
Note: No one is allowed to board a shuttle after the boarding time.
He arrives at time t and sometimes has to wait at the station. You are given a list of arrival times for n days.
Devise an algorithm to find him the shuttle with the least waiting time. (waiting time = boardingj - t , where j is the next shuttle. And boardingj >= t ) for each ti
If he also has access to the travel time of each shuttle. Can you help him find the shuttle which will help him reach his destination at the earliest ?
Return an array of shuttle indexes that Rahul took for n days.
brd = [10, 300, 600, 900, 1200, 1500, 1800, 2100]
dep = [30, 330, 630, 930, 1230, 1530, 1830, 2130]
sht = [60, 70, 75, 60, 80, 65, 70, 85 ]
print(" Boarding Time Departure Time Travel Time")
for r in range(0,len(brd)):
print("%3d%10d%25d%15d"%(r+1,brd[r],dep[r],sht[r]))
t = 301#int(input("Enter the Rahul's arrival time at station (HHMN format): "))
st =0
for i in range(0,len(brd)-1):
if(t>=brd[i] and t<= brd[i+1]):
a = (t//1000)
b = ((t%1000)//100)
c = (((t%1000)%100)//10)
d = (((t%1000)%100)%10)
print("Rahul's Arrival Time = %d%d:%d%d"%(a,b,c,d))
a = (brd[i+1]//1000)
b = ((brd[i+1]%1000)//100)
c = (((brd[i+1]%1000)%100)//10)
d = (((brd[i+1]%1000)%100)%10)
print("Available Train Boarding Time = %d%d:%d%d"%(a,b,c,d))
a = (dep[i+1]//1000)
b = ((dep[i+1]%1000)//100)
c = (((dep[i+1]%1000)%100)//10)
d = (((dep[i+1]%1000)%100)%10)
print("Available Train Dep. Time = %d%d:%d%d"%(a,b,c,d))
WH = a*10+b
WM = c*10+d
st = sht[i+1]
a = st//60
b = st%60
print("Travel Time by the Shuttle = %d Hours and %d Minutes"%(a,b))
a = (t//1000)
b = ((t%1000)//100)
c = (((t%1000)%100)//10)
d = (((t%1000)%100)%10)
AH = a*10 + b
AM = c*10 + d
WM = (WH*60 + WM) - (AH*60 + AM)
print("Waiting Time = %2d Houres and %2d Minutes"%(WM//60,WM%60))
Comments
Leave a comment