Imagine that there is a small network with a number of interconnected devices. Each connection has a latency parameter which is expressed in milliseconds. Your task is to write a program that will determine whether a signal can travel between two devices in a given amount of time or less.
-
The program should be executable from command line and accept one parameter - csv file path.
-
CSV file structure:
Format: Device From, Device To, Latency (milliseconds) Contents: A,B,10 A,C,20 B,D,100 C,D,30 D,E,10 E,F,1000
-
The program should then continually wait for user input. Format should be [Device From] [Device To] [Time] (e.g A F 1000 followed by ENTER key). If the signal can travel from A to F in 1000ms or less then output the signal path and total travel time in milliseconds otherwise print "Path not found". If user enters QUIT then terminate the program.
-
You are only required to output first path that meets the time constraint. It does not have to be the shortest path.
- Hints: Think of the best data structure to accommodate devices and connections and write your code accordingly.
$ composer install
$ php run.php [CSV FILE]
$ php run.php sample_data.csv
$ docker build -t app .
$ docker run --rm -it -v $(pwd):/app -w /app app composer install && php run.php sample_data.csv