A datacenter building is a large rectangle. We can consider the northwest corner as location 0,0 and mark the locations of the routers and servers as x,y (in feet).
There are two switches located (from the northwest corner of the room) at 100,100 and 300,300.
Both of the switches have plenty of empty slots and bandwidth.
We need to add 4 new servers, which will be placed at these locations:
50,50 250,300 150,100 50,200
The boss is cheap and wants to buy as little wire as possible.
The distance between two points on a XY grid is the hypotenuse of the right triangle defined by the two points and the intersection of the horizontal and vertical lines passing through those points.
In formula terms - given point 1 (x1, y1) and point 2 (x2, y2) the
sqrt ( (($x1 - $x2) * ($x1 - $x2)) + (($y1 - $y2) * ($y1 - $y2)) )
Your code will be simpler if you put the distance calculation in a procedure.
Write a script to determine which server to connect to which switch, and how much wire it will take.
The output should resemble this:
Connect system at 50 50 to router1 with 70.71067811865476 feet of wire Connect system at 250 300 to router2 with 50.0 feet of wire Connect system at 150 100 to router1 with 50.0 feet of wire Connect system at 50 200 to router1 with 111.80339887498948 feet of wire