3v4l.org

run code in 300+ PHP versions simultaneously
<?php test(2000); test(1845); test(2340); test(3000); // Examples: // Door 2000 1845 3000 // 615mm panel 1 3 5 // 495mm panel 3 0 0 // panel loss 100 0 75 function calcOptimalPanels ($doorHeight) { $bigHeight = 615; $smallHeight = 495; $bigFit = floor($doorHeight / $bigHeight); $smallFit = floor($doorHeight / $smallHeight); $options = []; for ($big = 0; $big <= $bigFit; $big++) { for ($small = 0; $small <= $smallFit; $small++) { $waste = $bigHeight * $big + $smallHeight * $small - $doorHeight; if ($waste === 0) // Get first combination without waste return getFormattedResult($big, $small, $waste); if ($waste < 0) // Omit combinations smaller then door continue; $options[$waste] = getFormattedResult($big, $small, $waste); } } $minWaste = min(array_keys($options)); return $options[$minWaste]; } function getFormattedResult($big, $small, $waste) { return ['615mm' => $big, '495mm' => $small, 'waste' => $waste]; } function test($doorHeight) { echo $doorHeight . ': ' . json_encode(calcOptimalPanels($doorHeight)) . "\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
2000: {"615mm":1,"495mm":3,"waste":100} 1845: {"615mm":3,"495mm":0,"waste":0} 2340: {"615mm":3,"495mm":1,"waste":0} 3000: {"615mm":1,"495mm":5,"waste":90}

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
159.06 ms | 405 KiB | 5 Q