$n) // 範囲外(プラス方向) ) { return FALSE; } $visited[] = $start; // ゴール到着 if ( $start == $n ) { return $time; } $bit = decbin($start); $counts = count_chars($bit, 1); $count = $counts[ord('1')]; $time++; return select_waypoint(move($start+$count, $visited, $time), move($start-$count, $visited, $time)); } function select_waypoint($a, $b) { if ( $a === FALSE ) { return $b; } else if ( $b === FALSE ) { return $a; } else if ( ($a === FALSE) && ($b === FALSE) ) { return FALSE; } else { return min($a, $b); } }