3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Supply clock values clockwise. // Keys can be anything you want to use to remember the positions. $clock = array( 'a' => 3, 'b' => 3, 'c' => 3, 'd' => 4, 'e' => 1, 'f' => 3, 'g' => 2, 'h' => 1, 'i' => 5, 'j' => 2, ); $positions = array_keys($clock); $values = array_values($clock); // Test all possible starting positions. for ($i = 0; $i < count($clock); ++$i) { $chain = test_clock($values, $i); // When the solution has all values, it's the right one. if (count($chain) == count($clock)) { break; } } // Use the user-supplied keys. $solution = array(); foreach ($chain as $position) { $solution[] = $positions[$position]; } print 'The solution is: ' . implode($solution, ' → ') . PHP_EOL; /** * Recursively test the clock based on a supplied position. * * @param array $values * The current values of the clock. * @param integer $i * The current position of the clock. * @param array $chain * The current possible solution. * * @return * An array of positions that represents a possible solution. */ function test_clock(array $values, $i, array $chain = array()) { // If the value of the position we're in is 0, we've already tested it. if ($values[$i] == 0) { return $chain; } // Find the next two positions. $position1 = $i + $values[$i]; $position2 = $i - $values[$i]; // Account for wraparound in the array. if ($position1 > count($values) - 1) { $position1 -= count($values); } if ($position2 < 0) { $position2 += count($values); } // Mark this position as tested. $values[$i] = 0; $chain[] = $i; // Test the first position. $solution = test_clock($values, $position1, $chain); // Don't bother checking the second position if the first is correct. if (count($solution) == count($values)) { return $solution; } // Test the second position. return test_clock($values, $position2, $chain); }

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.3.60.0110.00716.75
8.3.50.0120.00621.20
8.3.40.0110.00718.88
8.3.30.0070.00719.22
8.3.20.0030.00620.34
8.3.10.0040.00421.60
8.3.00.0120.00017.63
8.2.180.0110.00418.31
8.2.170.0150.00019.09
8.2.160.0070.01022.96
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0080.00026.16
8.2.120.0000.00819.48
8.2.110.0100.00019.13
8.2.100.0120.00017.78
8.2.90.0000.00819.17
8.2.80.0060.00317.97
8.2.70.0030.00517.48
8.2.60.0000.00817.80
8.2.50.0030.00518.07
8.2.40.0030.00519.95
8.2.30.0040.00418.16
8.2.20.0050.00317.92
8.2.10.0040.00418.24
8.2.00.0080.00017.74
8.1.280.0070.01025.92
8.1.270.0040.00420.32
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0030.00719.13
8.1.230.0070.00420.88
8.1.220.0000.00817.77
8.1.210.0050.00518.77
8.1.200.0040.00417.35
8.1.190.0040.00417.36
8.1.180.0000.00918.10
8.1.170.0030.00520.28
8.1.160.0050.00322.02
8.1.150.0000.00818.91
8.1.140.0000.00817.50
8.1.130.0000.00817.88
8.1.120.0040.00317.50
8.1.110.0040.00417.50
8.1.100.0000.00717.37
8.1.90.0040.00417.51
8.1.80.0040.00417.45
8.1.70.0030.00317.51
8.1.60.0060.00317.68
8.1.50.0000.00817.60
8.1.40.0040.00417.58
8.1.30.0030.00617.79
8.1.20.0030.00617.69
8.1.10.0030.00617.63
8.1.00.0080.00017.56
8.0.300.0000.00718.77
8.0.290.0090.00016.88
8.0.280.0030.00318.41
8.0.270.0030.00317.30
8.0.260.0050.00217.20
8.0.250.0000.00716.98
8.0.240.0080.00016.97
8.0.230.0000.00716.95
8.0.220.0070.00017.04
8.0.210.0050.00217.01
8.0.200.0040.00417.08
8.0.190.0070.00017.07
8.0.180.0070.00017.07
8.0.170.0070.00017.02
8.0.160.0000.00717.01
8.0.150.0030.00516.90
8.0.140.0060.00316.84
8.0.130.0060.00013.46
8.0.120.0060.00316.89
8.0.110.0000.00817.00
8.0.100.0050.00217.02
8.0.90.0040.00417.07
8.0.80.0120.00917.07
8.0.70.0040.00416.83
8.0.60.0020.00517.07
8.0.50.0040.00416.89
8.0.30.0120.01217.17
8.0.20.0120.00817.40
8.0.10.0000.00717.19
8.0.00.0100.00816.79
7.4.330.0030.00315.05
7.4.320.0030.00316.66
7.4.300.0070.00016.65
7.4.290.0040.00416.45
7.4.280.0000.00916.66
7.4.270.0000.00716.74
7.4.260.0040.00416.65
7.4.250.0070.00016.47
7.4.240.0040.00316.56
7.4.230.0050.00216.49
7.4.220.0130.00316.45
7.4.210.0070.00716.68
7.4.200.0030.00416.63
7.4.160.0140.00716.37
7.4.150.0060.01217.40
7.4.140.0150.00817.86
7.4.130.0120.00816.66
7.4.120.0080.01016.65
7.4.110.0110.00916.43
7.4.100.0070.01616.58
7.4.90.0090.00916.71
7.4.80.0100.01019.39
7.4.70.0170.00316.68
7.4.60.0130.00316.69
7.4.50.0040.00416.49
7.4.40.0150.00616.59
7.4.30.0100.01316.52
7.4.00.0090.00614.87
7.3.330.0000.00513.25
7.3.320.0080.00413.50
7.3.310.0000.00716.29
7.3.300.0070.00016.42
7.3.290.0050.00216.46
7.3.280.0050.01116.37
7.3.270.0090.00917.40
7.3.260.0100.01016.67
7.3.250.0070.01416.60
7.3.240.0060.01016.46
7.3.230.0100.01316.46
7.3.210.0190.00416.68
7.3.200.0030.01319.39
7.3.190.0060.01016.50
7.3.180.0090.00616.59
7.3.170.0070.01016.60
7.3.160.0160.00816.71
7.3.10.0030.01016.90
7.3.00.0040.00816.71
7.2.330.0130.01016.81
7.2.320.0110.00716.46
7.2.310.0070.01016.54
7.2.300.0070.01716.80
7.2.290.0020.00816.59
7.2.130.0070.00716.96
7.2.120.0110.00316.71
7.2.110.0000.01017.07
7.2.100.0000.01116.65
7.2.90.0090.00617.06
7.2.80.0040.01117.03
7.2.70.0070.00416.96
7.2.60.0120.00316.84
7.2.50.0070.00717.08
7.2.40.0070.01116.88
7.2.30.0040.00817.10
7.2.20.0030.01317.01
7.2.10.0110.00317.10
7.2.00.0080.00518.38
7.1.250.0000.01015.93
7.1.200.0090.00415.46
7.1.100.0000.01317.97
7.1.70.0000.00817.03
7.1.60.0060.01919.50
7.1.50.0070.01717.00
7.1.00.0100.07022.44
7.0.200.0030.01014.99
7.0.140.0070.03022.01
7.0.60.0130.03320.00
7.0.50.0100.05717.92
7.0.40.0130.07020.40
7.0.30.0500.03320.07
7.0.20.0170.04320.15
7.0.10.0330.07020.30
7.0.00.0070.04020.22
5.6.280.0030.07321.14
5.6.210.0130.07020.70
5.6.200.0170.07318.16
5.6.190.0070.09320.77
5.6.180.0230.06020.60
5.6.170.0170.08320.45
5.6.160.0100.08320.44
5.6.150.0100.08318.16
5.6.140.0030.08318.15
5.6.130.0030.06718.21
5.6.120.0070.04021.15
5.6.110.0130.08021.15
5.6.100.0100.03321.15
5.6.90.0130.08021.05
5.6.80.0070.08020.50
5.6.70.0300.07320.38
5.5.350.0300.07020.36
5.5.340.0170.05718.05
5.5.330.0070.07720.40
5.5.320.0300.07320.41
5.5.310.0070.05020.37
5.5.300.0030.03717.97
5.5.290.0070.07718.08
5.5.280.0170.04320.75
5.5.270.0030.08320.77
5.5.260.0100.07720.98
5.5.250.0070.03720.70
5.5.240.0100.03320.14
5.4.450.0330.06019.70
5.4.440.0900.05019.55
5.4.430.0970.05319.16
5.4.420.0930.06019.60
5.4.410.0130.07319.07
5.4.400.1470.08018.49
5.4.390.1530.07318.75
5.4.380.1530.07718.75
5.4.370.1270.06318.61
5.4.360.1230.06018.80
5.4.350.1430.04718.78
5.4.340.1400.05318.56
5.4.320.1600.05718.84
5.4.310.1330.05018.50
5.4.300.1570.07318.53
5.4.290.1330.06018.56
5.4.280.1400.08018.84
5.4.270.1330.05718.78
5.4.260.1430.04318.78
5.4.250.1200.05718.56
5.4.240.1530.07018.73
5.4.230.1300.05318.76
5.4.220.1400.06018.61
5.4.210.1270.07718.55
5.4.200.1430.06016.66
5.4.190.1070.05718.77
5.4.180.1100.05318.60
5.4.170.1300.04718.74
5.4.160.1500.06318.76
5.4.150.1730.06718.59
5.4.140.1300.05716.32
5.4.130.1200.05316.33
5.4.120.1430.04016.38
5.4.110.1200.06016.25
5.4.100.1470.05016.36
5.4.90.1330.05716.29
5.4.80.1400.04316.29
5.4.70.0200.04716.35
5.4.60.0200.04316.21
5.4.50.0670.05716.27
5.4.40.1100.07316.25
5.4.30.1400.06016.27
5.4.20.1470.05016.27
5.4.10.3370.05316.43
5.4.00.1370.04715.80
5.3.290.1300.06714.74
5.3.280.1430.06014.64
5.3.270.1530.05014.76
5.3.260.1100.06014.80
5.3.250.1170.05014.61
5.3.240.2700.05314.64
5.3.230.3000.05314.68
5.3.220.1630.06714.73
5.3.210.2030.06714.72
5.3.200.1330.04314.76
5.3.190.1570.06014.65
5.3.180.1370.07314.64
5.3.170.1030.08314.69
5.3.160.0600.05314.57
5.3.150.0370.06314.70
5.3.140.0830.05714.64
5.3.130.1330.05714.61
5.3.120.1270.04714.63
5.3.110.1030.05314.76
5.3.100.3330.05314.10
5.3.90.1370.05014.17
5.3.80.1170.07014.08
5.3.70.1130.04314.07
5.3.60.1070.05314.10
5.3.50.1270.05014.14
5.3.40.1070.05314.00
5.3.30.1400.05313.95
5.3.20.1030.05713.77
5.3.10.1070.05713.71
5.3.00.1070.05713.72
5.2.170.0900.05311.29
5.2.160.1130.04011.20
5.2.150.0930.04011.21
5.2.140.0870.04311.23
5.2.130.0800.04711.27
5.2.120.0870.04011.25
5.2.110.0930.03711.24
5.2.100.0870.04711.26
5.2.90.0970.04011.14
5.2.80.0800.05011.26
5.2.70.0530.04011.16
5.2.60.0130.03711.08
5.2.50.0130.04011.18
5.2.40.0170.03311.09
5.2.30.0030.04711.25
5.2.20.0600.05711.22
5.2.10.0800.05311.00
5.2.00.0900.05310.83
5.1.60.0770.04010.11
5.1.50.0730.03310.06
5.1.40.0730.03710.05
5.1.30.0700.03310.40
5.1.20.1000.05010.50
5.1.10.0670.04310.13
5.1.00.0830.04310.21
5.0.50.0400.0338.54
5.0.40.0470.0308.45
5.0.30.0470.0408.31
5.0.20.0400.0308.23
5.0.10.0400.0308.32
5.0.00.0470.0408.31
4.4.90.0400.0236.01
4.4.80.0300.0275.92
4.4.70.0400.0275.88
4.4.60.0430.0205.93
4.4.50.0370.0205.98
4.4.40.0430.0276.04
4.4.30.0200.0205.91
4.4.20.0330.0235.96
4.4.10.0330.0275.97
4.4.00.0430.0305.98
4.3.110.0300.0275.84
4.3.100.0330.0335.95
4.3.90.0370.0335.85
4.3.80.0330.0375.89
4.3.70.0330.0235.89
4.3.60.0330.0235.79
4.3.50.0370.0235.89
4.3.40.0330.0375.77
4.3.30.0230.0234.57
4.3.20.0130.0274.55
4.3.10.0130.0274.48
4.3.00.0100.0276.88

preferences:
52.12 ms | 401 KiB | 5 Q