<?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 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- 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}
preferences:
133.12 ms | 408 KiB | 5 Q