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' => '2', 'b' => '1', 'c' => '1', 'd' => '2', 'e' => '3', 'f' => '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.00416.75
8.3.50.0120.00721.13
8.3.40.0070.00718.97
8.3.30.0100.00719.21
8.3.20.0050.00320.24
8.3.10.0040.00421.91
8.3.00.0090.00019.51
8.2.180.0040.01118.29
8.2.170.0110.01118.94
8.2.160.0140.00722.96
8.2.150.0000.00724.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0040.00419.48
8.2.110.0090.00019.18
8.2.100.0120.00017.75
8.2.90.0000.00819.17
8.2.80.0050.00317.97
8.2.70.0000.00817.75
8.2.60.0040.00417.93
8.2.50.0040.00418.07
8.2.40.0030.00619.95
8.2.30.0030.00518.23
8.2.20.0000.00817.93
8.2.10.0030.00518.12
8.2.00.0040.00417.94
8.1.280.0040.01425.92
8.1.270.0000.00724.66
8.1.260.0060.00326.35
8.1.250.0070.00028.09
8.1.240.0090.00022.62
8.1.230.0060.00617.42
8.1.220.0000.00817.91
8.1.210.0000.00818.77
8.1.200.0000.01017.36
8.1.190.0050.00317.35
8.1.180.0080.00018.10
8.1.170.0050.00320.44
8.1.160.0040.00422.12
8.1.150.0030.00518.93
8.1.140.0080.00017.50
8.1.130.0000.00717.81
8.1.120.0000.00817.38
8.1.110.0040.00417.39
8.1.100.0050.00217.39
8.1.90.0040.00417.41
8.1.80.0040.00417.40
8.1.70.0000.00717.50
8.1.60.0050.00517.60
8.1.50.0030.00517.54
8.1.40.0000.00817.62
8.1.30.0000.00917.66
8.1.20.0040.00417.59
8.1.10.0050.00317.58
8.1.00.0040.00417.57
8.0.300.0000.00818.77
8.0.290.0000.00716.88
8.0.280.0020.00518.40
8.0.270.0000.00717.37
8.0.260.0060.00317.22
8.0.250.0000.00717.08
8.0.240.0040.00416.91
8.0.230.0000.00717.09
8.0.220.0070.00016.97
8.0.210.0040.00417.02
8.0.200.0000.00717.06
8.0.190.0000.00716.98
8.0.180.0000.00716.96
8.0.170.0040.00417.05
8.0.160.0070.00016.88
8.0.150.0040.00416.92
8.0.140.0040.00416.87
8.0.130.0030.00313.46
8.0.120.0080.00017.03
8.0.110.0040.00416.92
8.0.100.0000.00716.91
8.0.90.0030.00516.96
8.0.80.0060.00916.89
8.0.70.0040.00416.88
8.0.60.0040.00417.00
8.0.50.0000.00717.05
8.0.30.0160.00716.96
8.0.20.0090.00917.40
8.0.10.0050.00517.19
8.0.00.0050.01316.79
7.4.330.0070.00015.03
7.4.320.0030.00316.56
7.4.300.0030.00316.66
7.4.290.0060.00316.66
7.4.280.0050.00316.58
7.4.270.0040.00416.56
7.4.260.0030.00316.54
7.4.250.0070.00016.54
7.4.240.0030.00416.55
7.4.230.0070.00016.35
7.4.220.0130.01016.63
7.4.210.0050.00916.70
7.4.200.0000.00716.63
7.4.160.0000.02116.59
7.4.150.0070.01017.40
7.4.140.0140.01017.86
7.4.130.0070.01516.71
7.4.120.0090.00916.56
7.4.110.0070.01316.64
7.4.100.0180.00016.59
7.4.90.0090.01316.38
7.4.80.0120.00619.39
7.4.70.0070.01016.70
7.4.60.0130.00316.54
7.4.50.0030.00516.49
7.4.40.0040.01416.43
7.4.30.0120.00916.71
7.4.00.0070.01114.93
7.3.330.0000.00613.42
7.3.320.0100.00513.28
7.3.310.0070.00016.29
7.3.300.0000.00716.39
7.3.290.0030.00316.29
7.3.280.0080.00716.41
7.3.270.0120.00917.40
7.3.260.0160.00616.70
7.3.250.0110.00816.48
7.3.240.0000.01716.43
7.3.230.0170.00016.69
7.3.210.0030.01416.32
7.3.200.0110.00519.39
7.3.190.0110.00616.38
7.3.180.0100.00716.55
7.3.170.0110.01116.37
7.3.160.0120.00616.66
7.3.120.0070.01314.73
7.3.110.0000.01914.90
7.3.100.0030.01614.98
7.3.90.0030.00615.05
7.3.80.0070.01015.06
7.3.70.0130.00314.99
7.3.60.0130.00314.73
7.3.50.0080.00614.95
7.3.40.0030.00914.83
7.3.30.0080.00814.96
7.3.20.0040.01216.82
7.3.10.0080.00416.74
7.3.00.0060.00916.71
7.2.330.0180.00316.88
7.2.320.0070.01116.82
7.2.310.0080.00916.43
7.2.300.0090.00916.83
7.2.290.0180.00716.66
7.2.250.0140.00715.26
7.2.240.0030.01815.29
7.2.230.0000.01514.90
7.2.220.0030.01015.10
7.2.210.0060.00315.40
7.2.200.0070.00715.00
7.2.190.0000.01515.05
7.2.180.0000.00914.88
7.2.170.0000.01615.08
7.2.160.0050.00514.93
7.2.150.0000.01016.89
7.2.140.0000.01517.04
7.2.130.0030.00717.04
7.2.120.0060.00617.02
7.2.110.0030.01016.98
7.2.100.0090.00317.03
7.2.90.0030.00816.95
7.2.80.0060.00917.21
7.2.70.0070.00717.09
7.2.60.0050.00816.88
7.2.50.0130.00316.88
7.2.40.0100.00617.05
7.2.30.0090.00616.93
7.2.20.0000.01216.83
7.2.10.0060.00917.01
7.2.00.0050.00918.27
7.1.330.0030.01215.82
7.1.320.0030.00715.87
7.1.310.0030.01015.86
7.1.300.0060.00615.80
7.1.290.0070.01015.82
7.1.280.0040.00815.93
7.1.270.0030.00615.97
7.1.260.0040.00415.88
7.1.250.0100.00315.66
7.1.200.0040.01115.85
7.1.100.0060.00618.13
7.1.70.0060.00316.75
7.1.60.0140.01019.50
7.1.50.0000.02316.64
7.1.00.0030.07722.36
7.0.200.0110.00314.96
7.0.140.0000.07721.92
7.0.60.0030.04020.02
7.0.50.0130.08017.92
7.0.40.0170.07720.14
7.0.30.0470.07020.11
7.0.20.0270.04720.09
7.0.10.0370.06720.24
7.0.00.0100.08020.32
5.6.280.0030.07021.10
5.6.210.0100.08020.70
5.6.200.0100.08018.19
5.6.190.0170.04720.61
5.6.180.0330.07320.60
5.6.170.0330.08020.50
5.6.160.0030.04320.54
5.6.150.0030.06018.21
5.6.140.0030.08318.27
5.6.130.0070.04318.23
5.6.120.0000.08721.00
5.6.110.0100.05021.00
5.6.100.0030.05320.96
5.6.90.0030.05721.08
5.6.80.0130.07320.36
5.6.70.0330.06720.48
5.5.350.0270.07720.50
5.5.340.0070.06717.95
5.5.330.0130.07720.34
5.5.320.0230.05320.38
5.5.310.0230.06720.34
5.5.300.0030.03717.95
5.5.290.0070.08317.92
5.5.280.0100.06320.74
5.5.270.0070.08320.96
5.5.260.0100.04320.77
5.5.250.0070.04020.57
5.5.240.0070.03720.20
5.4.450.0230.08019.39
5.4.440.0030.06719.61
5.4.430.0600.08019.46
5.4.420.0330.06019.63
5.4.410.0130.07719.05
5.4.400.0300.05718.84
5.4.390.0370.05018.60
5.4.380.0400.05018.63
5.4.370.0300.05318.76
5.4.360.2400.06018.54
5.4.350.0370.05718.49
5.4.340.0330.06018.63
5.4.320.1800.06318.62
5.4.310.0270.07318.51
5.4.300.0430.05018.63
5.4.290.2070.06018.54
5.4.280.0330.06018.79
5.4.270.0270.06018.83
5.4.260.0300.05318.60
5.4.250.2600.05318.76
5.4.240.0400.05018.57
5.4.230.0430.04318.75
5.4.220.0470.04318.70
5.4.210.0270.05718.81
5.4.200.0300.04716.62
5.4.190.0230.05718.65
5.4.180.0300.05018.59
5.4.170.0400.04318.69
5.4.160.0400.04718.56
5.4.150.2130.04018.48
5.4.140.0400.06716.34
5.4.130.0500.05316.46
5.4.120.0270.05316.29
5.4.110.0230.05716.35
5.4.100.2030.06716.23
5.4.90.0470.04016.20
5.4.80.0330.05316.33
5.4.70.0270.06016.41
5.4.60.0370.04716.32
5.4.50.0300.05716.28
5.4.40.0230.05716.26
5.4.30.0370.05016.41
5.4.20.0330.05016.39
5.4.10.0400.04316.39
5.4.00.0370.05715.72
5.3.290.0270.06714.82
5.3.280.0370.06014.63
5.3.270.0430.04714.63
5.3.260.0400.04714.64
5.3.250.0330.05314.80
5.3.240.0370.05714.84
5.3.230.2570.05714.77
5.3.220.0370.05314.80
5.3.210.2000.06314.75
5.3.200.0270.05714.64
5.3.190.0330.05714.71
5.3.180.0530.05014.67
5.3.170.0330.06314.61
5.3.160.0330.07014.79
5.3.150.0270.07314.58
5.3.140.0430.05714.81
5.3.130.0430.06014.66
5.3.120.1000.06314.77
5.3.110.0870.06714.61
5.3.100.0470.06314.17
5.3.90.0300.06014.25
5.3.80.0300.06314.03
5.3.70.0230.06714.26
5.3.60.0230.05014.22
5.3.50.0200.04714.16
5.3.40.0130.05714.10
5.3.30.0170.05014.02
5.3.20.0330.04313.91
5.3.10.0270.05313.79
5.3.00.0330.04313.69
5.2.170.1770.04311.29
5.2.160.0300.04311.23
5.2.150.0330.04011.18
5.2.140.0200.04711.37
5.2.130.0330.03011.11
5.2.120.0270.03011.10
5.2.110.0270.03711.17
5.2.100.0270.03311.34
5.2.90.0130.04311.12
5.2.80.0170.05711.14
5.2.70.0200.04711.24
5.2.60.0270.05011.29
5.2.50.0300.03011.25
5.2.40.0130.04311.21
5.2.30.0130.05711.09
5.2.20.0700.04311.03
5.2.10.0170.04310.86
5.2.00.1730.04710.78
5.1.60.0370.04010.09
5.1.50.0270.03710.22
5.1.40.0130.04010.18
5.1.30.0100.03710.43
5.1.20.0070.04310.41
5.1.10.0770.04010.12
5.1.00.0670.04010.17
5.0.50.0370.0378.58
5.0.40.0370.0338.55
5.0.30.0230.0478.44
5.0.20.0430.0278.33
5.0.10.0270.0308.37
5.0.00.2000.0478.18
4.4.90.0800.0305.95
4.4.80.0370.0375.90
4.4.70.0430.0305.93
4.4.60.0370.0235.90
4.4.50.0300.0235.95
4.4.40.0330.0335.89
4.4.30.0270.0205.95
4.4.20.2170.0235.95
4.4.10.0430.0236.05
4.4.00.0330.0405.95
4.3.110.0400.0275.82
4.3.100.0400.0235.92
4.3.90.0430.0105.81
4.3.80.0300.0405.84
4.3.70.0330.0235.83
4.3.60.0400.0205.82
4.3.50.0300.0305.80
4.3.40.0270.0375.77
4.3.30.0100.0274.56
4.3.20.0200.0204.55
4.3.10.0130.0274.60
4.3.00.0170.0206.79

preferences:
52.77 ms | 401 KiB | 5 Q