This is not a required assignment. It is a challenge problem for those who have been asking for them. We are happy to work with you to figure these out, or to go over your solutions.
1 Challenge Problems: Programming With Flights
An airline maintains information on flights as a list of flight-values defined with the following data blocks:
data FlightInfo: |
| flight( |
from-city :: String, |
to-city :: String, |
departure :: Time, |
arrival :: Time |
) |
end |
|
# time is for 24-hour format |
data TimeData: |
| time( |
hours :: Number, |
mins :: Number |
) |
end |
Using these data blocks, write the following two functions:
A function is-valid-route which takes a starting city (string), ending city (string) a list of city names (strings) representing a possible route from the starting to the ending city, and a list of FlightInfo data (the airline schedule). The function produces a boolean indicating whether the given list of cities is a valid route based on the flight schedule.
For example, for a call
is-valid-route("Providence", "Orlando",
[list: "Providence", "Chicago", "Orlando"],
all-flights)
There would need to be a flight (in all-flights) from Providence to Chicago and a flight from Chicago to Orlando, such that the first flight arrives in Chicago before the second flight leaves. Don’t worry about layover/connection times. For this assignment, it would be fine if the second flight left a minute after the first flight landed.
There is no limit on the number of cities in a route, as long as the times work out.
A function find-route which takes a starting city (string), ending city (string), and a list of FlightInfo data and produces a list of FlightInfo representing a valid route from the starting to the ending cities. While the previous problem captured a route just with names, this one captures the route with the specific flights (assuming one might make a reservation based on this information).
The route you produce does NOT have to be the shortest route. It simply has to be a valid route. If there is no valid route between the two cities, return the empty list.
The flights problems are a non-trivial jump over the problems we have tried so far.
Follow the templates.
Think about tasks and create helper functions. There are multiple subtasks involved in finding routes. You will almost certainly need multiple functions to get this code clean.
Don’t be shy about asking for help. These problems are intended to stretch you a bit, because some of you are ready for that stretch. Sketch out a design of the functions you need, and feel free to email me asking whether you are on the right track as needed.