3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function getBatchSize($n) { if ($n <= 100) return false; for ($k = 1; $k <= 50; $k++) { // number of batches without the last (remainder) batch $x = floor((100.0 / (float)$k) - 1); // batch-size wihout the last batch $b = floor($n / $x); // remainder (batch-size of the last batch) $r = $n - ($b * $x); // remainder-limit (the acceptable remainder-size) $rl = ceil(($n / $x) * 2.0); if ($r <= $rl) break; } $pInc = floor(100.0 / $x); $pSum = $pInc * $x; $pR = 100 - $pSum; return array( 'b' => $b, 'x' => $x, 'r' => $r, 'pInc' => $pInc, 'pSum' => $pSum, 'pR' => $pR ); } $n = 101; $res = getBatchSize($n); if ($res === false) { printResult("n <= 100"); return; } echo "Resolve for n = " . $n . "<br />=> b = " . $res['b'] . ", x = " . $res['x'] . ", r = " . $res['r'] . ", pInc = " . $res['pInc'] . ", pSum = " . $res['pSum'] . ", pR = " . $res['pR']; echo "<br />"; for ($k = 1; $k <= 50; $k++) { $x = floor((100.0 / (float)$k) - 1.0); $b = floor($n / $x); $r = $n - ($b * $x); $rl = ceil(($n / $x) * 2.0); // $str = "k = " . $k; $str .= ", b = " . $b; $str .= ", x = " . $x; $str .= ": (" . $r . ' ≤ ' . $rl . ")"; if ($r <= $rl) $str .= " => [OK]"; echo '<br />' . $str; }
Output for 4.3.0 - 7.2.0
Resolve for n = 101<br />=> b = 1, x = 99, r = 2, pInc = 1, pSum = 99, pR = 1<br /><br />k = 1, b = 1, x = 99: (2 ≤ 3) => [OK]<br />k = 2, b = 2, x = 49: (3 ≤ 5) => [OK]<br />k = 3, b = 3, x = 32: (5 ≤ 7) => [OK]<br />k = 4, b = 4, x = 24: (5 ≤ 9) => [OK]<br />k = 5, b = 5, x = 19: (6 ≤ 11) => [OK]<br />k = 6, b = 6, x = 15: (11 ≤ 14) => [OK]<br />k = 7, b = 7, x = 13: (10 ≤ 16) => [OK]<br />k = 8, b = 9, x = 11: (2 ≤ 19) => [OK]<br />k = 9, b = 10, x = 10: (1 ≤ 21) => [OK]<br />k = 10, b = 11, x = 9: (2 ≤ 23) => [OK]<br />k = 11, b = 12, x = 8: (5 ≤ 26) => [OK]<br />k = 12, b = 14, x = 7: (3 ≤ 29) => [OK]<br />k = 13, b = 16, x = 6: (5 ≤ 34) => [OK]<br />k = 14, b = 16, x = 6: (5 ≤ 34) => [OK]<br />k = 15, b = 20, x = 5: (1 ≤ 41) => [OK]<br />k = 16, b = 20, x = 5: (1 ≤ 41) => [OK]<br />k = 17, b = 25, x = 4: (1 ≤ 51) => [OK]<br />k = 18, b = 25, x = 4: (1 ≤ 51) => [OK]<br />k = 19, b = 25, x = 4: (1 ≤ 51) => [OK]<br />k = 20, b = 25, x = 4: (1 ≤ 51) => [OK]<br />k = 21, b = 33, x = 3: (2 ≤ 68) => [OK]<br />k = 22, b = 33, x = 3: (2 ≤ 68) => [OK]<br />k = 23, b = 33, x = 3: (2 ≤ 68) => [OK]<br />k = 24, b = 33, x = 3: (2 ≤ 68) => [OK]<br />k = 25, b = 33, x = 3: (2 ≤ 68) => [OK]<br />k = 26, b = 50, x = 2: (1 ≤ 101) => [OK]<br />k = 27, b = 50, x = 2: (1 ≤ 101) => [OK]<br />k = 28, b = 50, x = 2: (1 ≤ 101) => [OK]<br />k = 29, b = 50, x = 2: (1 ≤ 101) => [OK]<br />k = 30, b = 50, x = 2: (1 ≤ 101) => [OK]<br />k = 31, b = 50, x = 2: (1 ≤ 101) => [OK]<br />k = 32, b = 50, x = 2: (1 ≤ 101) => [OK]<br />k = 33, b = 50, x = 2: (1 ≤ 101) => [OK]<br />k = 34, b = 101, x = 1: (0 ≤ 202) => [OK]<br />k = 35, b = 101, x = 1: (0 ≤ 202) => [OK]<br />k = 36, b = 101, x = 1: (0 ≤ 202) => [OK]<br />k = 37, b = 101, x = 1: (0 ≤ 202) => [OK]<br />k = 38, b = 101, x = 1: (0 ≤ 202) => [OK]<br />k = 39, b = 101, x = 1: (0 ≤ 202) => [OK]<br />k = 40, b = 101, x = 1: (0 ≤ 202) => [OK]<br />k = 41, b = 101, x = 1: (0 ≤ 202) => [OK]<br />k = 42, b = 101, x = 1: (0 ≤ 202) => [OK]<br />k = 43, b = 101, x = 1: (0 ≤ 202) => [OK]<br />k = 44, b = 101, x = 1: (0 ≤ 202) => [OK]<br />k = 45, b = 101, x = 1: (0 ≤ 202) => [OK]<br />k = 46, b = 101, x = 1: (0 ≤ 202) => [OK]<br />k = 47, b = 101, x = 1: (0 ≤ 202) => [OK]<br />k = 48, b = 101, x = 1: (0 ≤ 202) => [OK]<br />k = 49, b = 101, x = 1: (0 ≤ 202) => [OK]<br />k = 50, b = 101, x = 1: (0 ≤ 202) => [OK]