Simulate a fixed three-dimensional two-robot controller: for each robot, print the straight or detour route around the other robot's position, exactly following the stated rules.
Medium7SimulationImplementationGeometryBrute forceNo attempts yetTime limit1sMemory limit512 MBRainforest Inc. is opening a large automated warehouse in the north of the UK, in a place called Walthamstow.
The worker robots inside move in three dimensions. In one time step a robot either stays where it is or walks one metre along one of the six axis directions, so a robot that travels from (x1,y1,z1) to (x2,y2,z2) with nothing in its way needs ∣x2−x1∣+∣y2−y1∣+∣z2−z1∣ steps.
The robots are impeccably polite. When two of them meet head on, they settle it without a word and one steps aside so the other can pass.
A robot always stands on integer coordinates. Two robots must never stand on the same coordinates, and two robots must never exchange positions in one time step. All moves of a time step happen at the same instant.
The test run of the warehouse has two robots installed. The controller plans them with one fixed procedure, written out in the output section, and your program has to reproduce that plan exactly.
The first line has six space separated integers x0 y0 z0 x1 y1 z1. The first three are the start position (x0,y0,z0) of robot 1 and the last three are its end position (x1,y1,z1). The second line gives the six values of robot 2 in the same format. Every coordinate satisfies −1000≤x,y,z≤1000.
The two robots start at different positions and end at different positions. One robot may start and end at the same position.
Print the plan of the controller. Counting from 0, line T has six space separated integers: the position of robot 1 at time T followed by the position of robot 2 at time T. The first line holds the two start positions, the last line holds the two end positions, and between two consecutive lines a robot moves at most one metre.
The controller walks one robot at a time and leaves the other standing. Two definitions come first.
The straight route from p to q is the list of positions that begins at p, changes the x coordinate one step at a time until it matches the x coordinate of q, then changes the y coordinate the same way, then the z coordinate, and so ends at q.
The safe route from p to q around a blocked position m, where m equals neither p nor q, is fixed like this. If the straight route from p to q does not contain m, that route is the safe route. If it does contain m, check the six offsets (1,0,0), (−1,0,0), (0,1,0), (0,−1,0), (0,0,1), (0,0,−1) in this order and take the first offset s for which the straight route from p+s to q+s does not contain m. Such an offset always exists. The safe route is then p, every position of the straight route from p+s to q+s, and q, in that order.
Write a0 and a1 for the start and the end of robot 1, and b0 and b1 for those of robot 2. The controller applies the first rule whose condition holds.
While a robot walks a route, print one line for every position of the route except the first one, and the robot that is not walking repeats its position on those lines. A route of a single position prints no line.