...
for ($i=0; $i<$n; $i++) {
if ($n - $i < $length_best) {
echo '<br/><br/>End = ' . $i . '. Saved ' . ($n - $i) . ' steps.';
break;
}
if ($arr[$i] == 0 && $last == 0) {
$length++;
if ($length > $length_best) {
$length_best = $length;
$first_best = $first;
$last_best = $i;
}
} else if ($arr[$i] == 0 && $last != 0) {
// optimalizace
if ($length_best > 0 && $arr[$i+$length_best] != 0) {
echo '<br/>Jump from ' . $i . ' -> ' . ($length_best + $i);
$i += $length_best;
$save += $length_best;
}
$first = $i;
$length = 1;
} else {
$first = -1;
$length = 0;
}
$last = $arr[$i];
}
...
function reduce () {
if (parseInt($('#a_no').text()) > 0) {
$('#a_no').text(parseInt($('#a_no').text()) - 1);
} else {
window.clearInterval(red);
$('#a_add').css('visibility', 'hidden');
echo('všechny body byly pro nečinnost ztraceny...', 5000);
stop = run = false;
}