0) { $m = array_pop($queue); $bc = substr_count(decbin($m), 1); $move = $m - $bc; if ($move> 0 && ($a[$move] == -1 || $a[$move] > $a[$m] + 1)) { $a[$move] = $a[$m] + 1; array_unshift($queue, $move); } $move = $m + $bc; if ($move<= $n && ($a[$move] == -1 || $a[$move] > $a[$m] + 1)) { $a[$move] = $a[$m] + 1; array_unshift($queue, $move); } } print $a[$n];