3v4l.org

run code in 300+ PHP versions simultaneously
<?php $candiesTests = [ [1, 1, 2, 3], // Test1 => 1,3 [1, 1, 2, 3, 4], // Test2 => 1,4 [1, 1, 2, 2, 3, 4, 5, 5], // Test3 => 1,2,5,5 [1, 1, 2, 2, 3, 4, 5, 5, 1, 1, 5], // Test4 => 1,1,1,2,5 ]; function distributeCandies(array $candies): array { $quota = ceil(count($candies) / 2); // Berit's share $adam = []; // fill first $berit = []; // the leftovers $candyCounts = array_count_values($candies); ksort($candyCounts); while ($candyCounts) { foreach ($candyCounts as $candy => &$count) { $adam[] = $candy; --$count; if (!$count) { unset($candyCounts[$candy]); } if (count($adam) == $quota) { break 2; } } } foreach ($candyCounts as $candy => $count) { array_push($berit, ...array_fill(0, $count, $candy)); } return [$adam, $berit]; } foreach ($candiesTests as $candies) { $distribution = distributeCandies($candies); echo 'Adams candies: ' . implode(', ', $distribution[0]) . PHP_EOL . 'Berits candies: ' . implode(', ', $distribution[1]) . PHP_EOL . '---' . 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.5.20.0100.00719.62
8.5.10.0100.00720.19
8.5.00.0120.01220.05
8.4.170.0080.01523.91
8.4.160.0110.01323.80
8.4.150.0020.00014.05
8.4.140.0120.01017.67
8.4.130.0040.00518.73
8.4.120.0130.00824.32
8.4.110.0130.00918.97
8.4.100.0140.00818.66
8.4.90.0140.00720.56
8.4.80.0060.00718.86
8.4.70.0080.01019.00
8.4.60.0130.00920.31
8.4.50.0090.01120.63
8.4.40.0100.01019.43
8.4.30.0100.01020.52
8.4.20.0000.00817.98
8.4.10.0030.00723.64
8.3.290.0050.01318.45
8.3.280.0110.00818.37
8.3.270.0140.01116.61
8.3.260.0150.00516.41
8.3.250.0090.00919.15
8.3.240.0060.00317.23
8.3.230.0070.01216.68
8.3.220.0130.00319.03
8.3.210.0110.00718.47
8.3.200.0060.00316.67
8.3.190.0050.00319.21
8.3.180.0100.00818.88
8.3.170.0100.00917.29
8.3.160.0110.00316.45
8.3.150.0160.00316.56
8.3.140.0060.00316.41
8.3.130.0120.00016.54
8.3.120.0060.00318.83
8.3.110.0030.00618.43
8.3.100.0030.00724.06
8.3.90.0080.00026.77
8.3.80.0090.00018.55
8.3.70.0130.00318.36
8.3.60.0120.00616.63
8.3.50.0170.00320.20
8.3.40.0070.01120.30
8.3.30.0120.00318.88
8.3.20.0080.00024.18
8.3.10.0000.00724.66
8.3.00.0040.00426.16
8.2.300.0090.01018.22
8.2.290.0110.00820.21
8.2.280.0110.00820.14
8.2.270.0120.00316.52
8.2.260.0100.00717.30
8.2.250.0050.00316.68
8.2.240.0030.00616.98
8.2.230.0080.00020.94
8.2.220.0030.00637.54
8.2.210.0040.00426.77
8.2.200.0060.00316.63
8.2.190.0120.00916.58
8.2.180.0110.00325.92
8.2.170.0070.00722.96
8.2.160.0040.01122.96
8.2.150.0070.00025.66
8.2.140.0040.00424.66
8.2.130.0050.00326.16
8.2.120.0060.00326.16
8.2.110.0100.00021.04
8.2.100.0090.00317.91
8.2.90.0000.00820.78
8.2.80.0000.00820.54
8.2.70.0050.00317.75
8.2.60.0050.00317.93
8.2.50.0040.00818.05
8.2.40.0000.00818.22
8.2.30.0040.00418.27
8.2.20.0040.00419.43
8.2.10.0040.00418.16
8.2.00.0030.00319.25
8.1.340.0100.01017.65
8.1.330.0090.00921.82
8.1.320.0100.00917.89
8.1.310.0120.00616.58
8.1.300.0030.00617.65
8.1.290.0040.00830.84
8.1.280.0090.01225.92
8.1.270.0000.00824.66
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0070.00322.20
8.1.230.0090.00320.85
8.1.220.0040.00417.74
8.1.210.0040.00418.96
8.1.200.0080.00017.47
8.1.190.0060.00317.22
8.1.180.0040.00418.10
8.1.170.0040.00418.49
8.1.160.0000.00718.83
8.1.150.0030.00618.70
8.1.140.0040.00417.51
8.1.130.0000.00720.69
8.1.120.0000.00717.50
8.1.110.0140.00017.48
8.1.100.0080.00817.50
8.1.90.0160.00017.38
8.1.80.0110.00417.51
8.1.70.0070.00717.53
8.1.60.0150.00417.60
8.1.50.0110.00717.55
8.1.40.0140.00317.59
8.1.30.0070.00917.56
8.1.20.0090.00917.71
8.1.10.0150.00317.54
8.1.00.0150.00317.51
8.0.300.0040.00420.23
8.0.290.0060.00316.60
8.0.280.0030.00320.21
8.0.270.0000.00717.31
8.0.260.0060.00018.52
8.0.250.0040.00416.89
8.0.240.0110.00317.01
8.0.230.0060.00916.95
8.0.220.0070.00716.91
8.0.210.0070.00716.96
8.0.200.0060.00916.81
8.0.190.0040.01116.98
8.0.180.0110.00416.87
8.0.170.0070.00716.77
8.0.160.0150.00016.94
8.0.150.0130.00216.85
8.0.140.0150.00016.80
8.0.130.0080.00816.71
8.0.120.0120.00316.94
8.0.110.0150.00016.95
8.0.100.0080.00916.84
8.0.90.0140.00316.92
8.0.80.0150.00016.85
8.0.70.0120.00316.89
8.0.60.0110.00416.81
8.0.50.0100.00516.92
8.0.30.0120.00416.88
8.0.20.0100.00516.86
8.0.10.0050.00916.95
7.4.330.0000.00515.55
7.4.320.0110.00416.59
7.4.300.0070.00416.64
7.4.290.0150.00016.53
7.4.280.0050.00516.53
7.4.270.0000.00816.61
7.4.260.0060.00916.45
7.4.250.0120.00416.63
7.4.240.0070.00716.66
7.4.230.0120.00316.62
7.4.220.0150.00016.56
7.4.210.0090.00616.64
7.4.200.0090.00616.38
7.4.190.0070.00716.56
7.4.180.0100.00516.68
7.4.160.0070.00716.48
7.4.150.0110.00416.39
7.4.140.0080.00516.46
7.4.130.0100.00316.50
7.4.120.0050.00916.62
7.4.110.0060.00716.53
7.4.100.0110.00416.55
7.4.90.0140.00016.49
7.4.80.0110.00416.54
7.4.70.0120.00216.36
7.4.60.0100.00416.52
7.4.50.0080.00516.38
7.4.40.0080.00516.50
7.4.30.0070.00716.35
7.4.20.0100.00416.45
7.4.10.0090.00316.52
7.4.00.0000.01116.50

preferences:
38.27 ms | 403 KiB | 5 Q