static void Main(string[] args) { var currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var inputFiles = Directory.GetFiles(Path.Combine(currentDirectory, "Input")); foreach (var inputFile in inputFiles) { Console.WriteLine("Processing " + inputFile); Console.WriteLine(); var input = ReadFromFile(inputFile); var map = new TrainMap(); map.Parse(input); ExecuteFindDistanceOfRoute(map, "A", "B", "C"); ExecuteFindDistanceOfRoute(map, "A", "D"); ExecuteFindDistanceOfRoute(map, "A", "D", "C"); ExecuteFindDistanceOfRoute(map, "A", "E", "B", "C", "D"); ExecuteFindDistanceOfRoute(map, "A", "E", "C"); var fromCToCWithMax3Stops = map.FindRoutesBetween("C", "C", (routeLength, routeDistance) => routeLength <= 3, (routeLength, routeDistance) => routeLength > 3); Console.WriteLine("The number of trips starting at C and ending at C with a maximum of 3 stops: " + fromCToCWithMax3Stops.Count); var fromAToCWithExactly4Stops = map.FindRoutesBetween("A", "C", (routeLength, routeDistance) => routeLength == 4, (routeLength, routeDistance) => routeLength > 4); Console.WriteLine("The number of trips starting at A and ending at C with exactly 4 stops: " + fromAToCWithExactly4Stops.Count); var shortestRouteFromAToC = map.FindShortestDistance("A", "C"); Console.WriteLine("The length of the shortest route from A to C: " + DistanceToString(shortestRouteFromAToC)); var shortestRouteFromBToB = map.FindShortestDistance("B", "B"); Console.WriteLine("The length of the shortest route from B to B: " + DistanceToString(shortestRouteFromBToB)); var fromCToCWithDistanceLessThan30 = map.FindRoutesBetween("C", "C", (routeLength, routeDistance) => routeDistance < 30, (routeLength, routeDistance) => routeDistance >= 30); Console.WriteLine("The number of different routes from C to C with a distance of less than 30: " + fromCToCWithDistanceLessThan30.Count); Console.WriteLine("==============================="); } }
public void SetUp() { _map = new TrainMap(); _map.Parse("AB5, BC4, CD8, DC8, DE6, AD5, CE2, EB3, AE7"); }