with the php language at the third testcase is a bug, with the code below I solve the first and second testcase, but the third and fourth is impossible, my variable “torX” is increasing in one turn from 4 to 17 for the third level, and for the fourth the programm doesn’t change direction, it goes in the opposit direction:
<?php
fscanf(STDIN, "%d %d %d %d",
$lightX, // the X position of the light of power
$lightY, // the Y position of the light of power
$initialTX, // Thor's starting X position
$initialTY // Thor's starting Y position
);
$torX = $initialTX;
$torY = $initialTY;
$turn = 0;
$s = 0;
$n = 0;
while (TRUE)
{
$turn++;
$x = "";
$y = "";
if($torX < $lightX){
$x = "E";
$torX = $torX + 1;
}elseif($torX > $lightX){
$x = "W";
$torX = $torX - 1;
}
if($torY < $lightY){
$y = "S";
$torY += $torY + 1;
$s = $s + 1;
}elseif($torY > $lightY){
$y = "N";
$torY = $torY - 1;
$n = $n + 1;
}
if($turn < 13 && $torY == 17){
$torY -= $turn;
}
echo($y.$x."\n");
error_log(var_export($torY, true));
}
and the ouput:
Standard Error Stream: 9 19 18 13 27 26 25 24 23 22 21 20 19 18 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 ...
?>