$i_start ? "LR" : "UL"; $move2 = $i_end > $i_start ? "LL" : "UR"; for($i = 0; $i < $i_d / 4; $i++){ $moves[] = $move1; $moves[] = $move2; } } } else if($i_d % 2 == 0){ $move = $i_end > $i_start ? "LR" : "UL"; for($i = 0; $i < $i_d / 2; $i++){ if($i_end > $i_start){ $moves[] = "LR"; $i_start += 2; $j_start += 1; } else{ $moves[] = "UL"; $i_start -= 2; $j_start -= 1; } } if($i_start != $i_end || $j_start != $j_end){ $nextMoves = moves($n, $i_start, $j_start, $i_end, $j_end); $moves = !empty($nextMoves) ? array_merge($moves, $nextMoves) : array(); } } return $moves; } fscanf($handle, "%i",$n); fscanf($handle, "%i %i %i %i", $i_start, $j_start, $i_end, $j_end); printShortestPath($n, $i_start, $j_start, $i_end, $j_end); ?>