3v4l.org

run code in 300+ PHP versions simultaneously
<?php function addBills(&$change, $value, $count) // add 'count' bills of 'value' to the 'change' array { $change = array_merge($change, array_fill(0, $count, $value)); } function removeBill(&$change, $value) // remove one bill of 'value' from the 'change' array { $key = array_search($value, $change); if ($key !== false) { unset($change[$key]); } } function getChangeTotal($change) // get the total vlaue of the 'change' array { return array_sum($change); } function findMinimum($bills, $wantedTotal, $change = []) { // without bills there's nothing to do if (count($bills) == 0) { return $change; } // get the next smaller bill $value = array_pop($bills); // how many of those will fit? $count = intdiv($wantedTotal - getChangeTotal($change), $value); if ($count > 0) { // add as many bills as will fit addBills($change, $value, $count); while ($count > 0) { // can we find more change? $change = findMinimum($bills, $wantedTotal, $change); // did we reach the wanted total? if ($wantedTotal == getChangeTotal($change)) { return $change; } else { // we have to use smaller bills $count--; removeBill($change, $value); } } } // try a smaller bill return findMinimum($bills, $wantedTotal, $change); } $bills = [2, 5, 10]; print_r(findMinimum($bills, 23)); /* $change = addBills([2,3], 4, 3); print_r($change); print_r(removeBill($change, 4)); */

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.120.0060.00324.21
8.4.110.0130.00818.84
8.4.100.0110.00918.84
8.4.90.0100.01120.52
8.4.80.0080.01218.50
8.4.70.0110.01019.64
8.4.60.0140.00919.02
8.4.50.0140.00519.48
8.4.40.0130.01017.54
8.4.30.0060.00318.95
8.4.20.0170.00317.99
8.4.10.0090.00619.25
8.3.250.0090.00819.04
8.3.240.0120.00717.06
8.3.230.0100.00916.45
8.3.220.0090.01018.86
8.3.210.0080.00716.66
8.3.200.0050.00416.65
8.3.190.0110.00818.53
8.3.180.0110.00816.73
8.3.170.0040.01118.83
8.3.160.0060.00618.40
8.3.150.0060.01218.36
8.3.140.0040.01420.54
8.3.130.0030.00518.57
8.3.120.0060.00319.18
8.3.110.0000.00820.94
8.3.100.0090.00024.06
8.3.90.0070.01126.77
8.3.80.0060.00317.97
8.3.70.0030.01316.48
8.3.60.0100.01018.43
8.3.50.0090.01316.59
8.3.40.0070.00720.03
8.3.30.0030.01021.89
8.3.20.0080.00024.18
8.3.10.0080.00024.66
8.3.00.0080.01126.35
8.2.290.0100.00920.55
8.2.280.0120.00718.28
8.2.270.0070.01117.36
8.2.260.0110.00718.17
8.2.250.0100.00717.04
8.2.240.0000.00917.26
8.2.230.0080.00022.58
8.2.220.0070.00337.54
8.2.210.0080.00026.77
8.2.200.0060.00318.41
8.2.190.0150.00318.54
8.2.180.0110.00718.06
8.2.170.0000.01519.11
8.2.160.0080.01322.96
8.2.150.0120.00325.66
8.2.140.0040.00424.66
8.2.130.0060.01226.35
8.2.120.0070.01026.35
8.2.110.0100.00726.35
8.2.100.0150.00626.35
8.2.90.0040.01126.35
8.2.80.0070.01426.35
8.2.70.0120.00326.35
8.2.60.0040.01226.35
8.2.50.0070.01026.35
8.2.40.0120.00626.35
8.2.30.0110.00026.35
8.2.20.0000.01226.35
8.2.10.0090.00026.35
8.2.00.0040.00426.35
8.1.330.0100.00921.64
8.1.320.0060.01215.96
8.1.310.0000.01518.42
8.1.300.0090.00918.12
8.1.290.0000.00930.84
8.1.280.0140.00425.92
8.1.270.0050.00324.66
8.1.260.0080.00026.35
8.1.250.0080.00026.35
8.1.240.0030.00626.35
8.1.230.0040.00426.35
8.1.220.0040.00426.35
8.1.210.0080.00026.35
8.1.200.0000.00826.35
8.1.190.0080.00026.35
8.1.180.0050.00326.35
8.1.170.0080.00026.35
8.1.160.0070.00326.35
8.1.150.0040.00426.35
8.1.140.0040.00426.35
8.1.130.0040.00426.35
8.1.120.0050.00326.35
8.1.110.0050.00326.35
8.1.100.0050.00326.35
8.1.90.0030.00526.35
8.1.80.0070.00026.35
8.1.70.0060.00326.35
8.1.60.0090.00026.35
8.1.50.0060.00326.35
8.1.40.0050.00326.35
8.1.30.0050.00326.35
8.1.20.0050.00326.35
8.1.10.0050.00326.35
8.1.00.0000.00826.35

preferences:
27.6 ms | 403 KiB | 5 Q