3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getCoins(int $totalAmount, $denominations = [2 ,5, 10]){ $amtPossible = []; foreach($denominations as $d){ $amtPossible[ $d ]= [1, $d]; for($i = $d + 1; $i <= $totalAmount; ++$i){ if(isset($amtPossible[ $i - $d ])){ if(!isset($amtPossible[ $i ]) || $amtPossible[ $i ][0] > 1 + $amtPossible[ $i - $d ][0]){ $amtPossible[ $i ][0] = 1 + $amtPossible[ $i - $d ][0]; $amtPossible[ $i ][1] = $d; } } } } if(!isset($amtPossible[ $totalAmount ])){ throw new \Exception("$totalAmount is not possible with the denominations ". implode(",", $denominations)); } $coins = []; while($totalAmount > 0){ $coins[] = $amtPossible[ $totalAmount ][1]; $totalAmount -= $amtPossible[ $totalAmount ][1]; } return $coins; } foreach([10, 11, 21, 23, 31, 3] as $test){ try{ echo $test, " => ", implode(", ", getCoins($test)), PHP_EOL; }catch(\Exception $e){ echo $e->getMessage(), PHP_EOL; } }

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.130.0110.00917.60
8.4.120.0070.00524.24
8.4.110.0090.01124.16
8.4.100.0120.00918.98
8.4.90.0030.00720.59
8.4.80.0060.00218.69
8.4.70.0100.01017.91
8.4.60.0150.00518.69
8.4.50.0150.00520.38
8.4.40.0120.00817.84
8.4.30.0160.00318.64
8.4.20.0150.00617.83
8.4.10.0090.01219.82
8.3.260.0150.00316.77
8.3.250.0140.00519.05
8.3.240.0110.00717.18
8.3.230.0090.01016.79
8.3.220.0110.00419.03
8.3.210.0020.00516.68
8.3.200.0040.00516.69
8.3.190.0090.01117.34
8.3.180.0090.00817.25
8.3.170.0140.00418.82
8.3.160.0150.00318.66
8.3.150.0090.00918.54
8.3.140.0120.00316.75
8.3.130.0030.00618.39
8.3.120.0070.01318.98
8.3.110.0030.00820.94
8.3.100.0060.00324.06
8.3.90.0130.00626.77
8.3.80.0040.00418.68
8.3.70.0110.00716.75
8.3.60.0040.01518.43
8.3.50.0090.00616.72
8.3.40.0120.00320.03
8.3.30.0030.01021.73
8.3.20.0000.00924.18
8.3.10.0030.00624.66
8.3.00.0060.00326.35
8.2.290.0120.00720.46
8.2.280.0110.00818.45
8.2.270.0160.00317.20
8.2.260.0130.00718.13
8.2.250.0040.00416.72
8.2.240.0080.00019.00
8.2.230.0040.00422.58
8.2.220.0030.00637.54
8.2.210.0040.00426.77
8.2.200.0110.00016.50
8.2.190.0130.00316.63
8.2.180.0110.00716.88
8.2.170.0040.01618.91
8.2.160.0040.01122.96
8.2.150.0040.00425.66
8.2.140.0030.00624.66
8.2.130.0000.00926.35
8.2.120.0080.00026.35
8.2.110.0060.00326.35
8.2.100.0060.00326.35
8.2.90.0030.00626.35
8.2.80.0090.00026.35
8.2.70.0060.00326.35
8.2.60.0060.00326.35
8.2.50.0030.00626.35
8.2.40.0050.00526.35
8.2.30.0030.00626.35
8.2.20.0060.00326.35
8.2.10.0000.00926.35
8.2.00.0030.00626.35
8.1.330.0130.00821.88
8.1.320.0110.00816.00
8.1.310.0130.00318.68
8.1.300.0070.00318.04
8.1.290.0070.01030.84
8.1.280.0070.01425.92
8.1.270.0080.00024.66
8.1.260.0040.00426.35
8.1.250.0060.00326.35
8.1.240.0090.00026.35
8.1.230.0040.00426.35
8.1.220.0060.00326.35
8.1.210.0030.00626.35
8.1.200.0000.00926.35
8.1.190.0060.00326.35
8.1.180.0060.00326.35
8.1.170.0000.00926.35
8.1.160.0040.00426.35
8.1.150.0060.00326.35
8.1.140.0030.00626.35
8.1.130.0060.00326.35
8.1.120.0040.00426.35
8.1.110.0060.00326.35
8.1.100.0000.00926.35
8.1.90.0060.00326.35
8.1.80.0060.00326.35
8.1.70.0040.00426.35
8.1.60.0080.00026.35
8.1.50.0090.00026.35
8.1.40.0060.00326.35
8.1.30.0030.00626.35
8.1.20.0060.00326.35
8.1.10.0060.00326.35
8.1.00.0050.00526.35

preferences:
26.34 ms | 403 KiB | 5 Q