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' => 2, 'c' => 5, 'd' => 2, 'e' => 4, 'f' => 4, 'g' => 2, 'h' => 3, 'i' => 4, 'j' => 3, ); $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.40.0100.00619.02
8.3.30.0110.00419.21
8.3.20.0090.00020.46
8.3.10.0000.00821.91
8.3.00.0050.00519.27
8.2.170.0170.00318.95
8.2.160.0100.00322.96
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0000.00926.16
8.2.120.0050.00319.48
8.2.110.0060.00322.18
8.2.100.0110.00019.70
8.2.90.0080.00017.86
8.2.80.0000.00818.81
8.2.70.0040.00418.05
8.2.60.0000.00817.93
8.2.50.0000.00918.10
8.2.40.0030.00620.63
8.2.30.0050.00318.12
8.2.20.0040.00417.75
8.2.10.0030.00518.12
8.2.00.0040.00417.80
8.1.270.0040.00424.66
8.1.260.0070.00026.35
8.1.250.0080.00028.09
8.1.240.0030.00620.54
8.1.230.0110.00017.77
8.1.220.0050.00317.79
8.1.210.0000.00818.77
8.1.200.0080.00017.36
8.1.190.0060.00317.41
8.1.180.0050.00318.10
8.1.170.0090.00018.50
8.1.160.0040.00422.18
8.1.150.0060.00318.93
8.1.140.0080.00017.41
8.1.130.0000.00817.98
8.1.120.0000.00717.56
8.1.110.0030.00317.38
8.1.100.0070.00017.52
8.1.90.0000.00717.42
8.1.80.0040.00417.41
8.1.70.0030.00517.50
8.1.60.0030.00617.68
8.1.50.0060.00317.45
8.1.40.0050.00217.58
8.1.30.0000.00917.68
8.1.20.0030.00517.63
8.1.10.0000.00817.44
8.1.00.0060.00317.62
8.0.300.0040.00418.77
8.0.290.0050.00216.88
8.0.280.0000.00718.41
8.0.270.0080.00017.21
8.0.260.0040.00417.24
8.0.250.0000.00717.10
8.0.240.0040.00416.96
8.0.230.0000.00716.96
8.0.220.0030.00316.87
8.0.210.0000.00816.93
8.0.200.0040.00417.01
8.0.190.0000.00717.02
8.0.180.0040.00416.98
8.0.170.0020.00517.09
8.0.160.0030.00317.06
8.0.150.0000.00717.02
8.0.140.0030.00716.89
8.0.130.0030.00313.40
8.0.120.0000.00816.98
8.0.110.0030.00516.88
8.0.100.0040.00416.82
8.0.90.0040.00416.95
8.0.80.0080.00816.95
8.0.70.0000.00817.00
8.0.60.0030.00517.04
8.0.50.0040.00416.95
8.0.30.0140.00617.21
8.0.20.0100.01317.40
8.0.10.0040.00417.02
8.0.00.0080.01016.98
7.4.330.0050.00315.03
7.4.320.0070.00016.70
7.4.300.0000.00616.46
7.4.290.0070.00316.49
7.4.280.0040.00416.55
7.4.270.0060.00016.71
7.4.260.0030.00316.64
7.4.250.0000.00716.52
7.4.240.0020.00516.56
7.4.230.0030.00316.66
7.4.220.0100.01016.65
7.4.210.0120.00316.60
7.4.200.0030.00316.64
7.4.160.0070.00716.56
7.4.150.0070.01017.40
7.4.140.0070.01317.86
7.4.130.0120.01116.49
7.4.120.0090.01016.71
7.4.110.0090.01216.52
7.4.100.0160.00316.61
7.4.90.0030.01516.61
7.4.80.0060.00919.39
7.4.70.0100.00716.57
7.4.60.0030.01316.59
7.4.50.0040.00416.70
7.4.40.0150.00616.62
7.4.30.0090.01216.43
7.4.10.0040.01314.90
7.4.00.0080.01014.93
7.3.330.0050.00013.25
7.3.320.0100.00313.28
7.3.310.0000.00716.41
7.3.300.0000.00716.38
7.3.290.0070.00016.35
7.3.280.0080.00916.35
7.3.270.0050.01117.40
7.3.260.0100.01316.37
7.3.250.0080.01116.50
7.3.240.0200.00016.46
7.3.230.0090.00916.39
7.3.210.0000.02016.45
7.3.200.0120.00919.39
7.3.190.0030.01316.72
7.3.180.0100.00616.58
7.3.170.0100.00616.77
7.3.160.0060.01516.53
7.3.130.0110.00514.70
7.3.120.0070.01014.82
7.3.110.0090.00814.82
7.3.100.0080.00814.97
7.3.90.0090.00614.74
7.3.80.0120.00214.95
7.3.70.0110.00614.78
7.3.60.0080.00714.68
7.3.50.0080.00614.73
7.3.40.0050.00914.83
7.3.30.0070.00914.73
7.3.20.0080.00616.11
7.3.10.0070.00816.15
7.3.00.0090.00715.99
7.2.330.0140.01016.87
7.2.320.0110.00816.66
7.2.310.0060.01116.61
7.2.300.0150.00316.60
7.2.290.0150.01116.59
7.2.260.0050.01215.07
7.2.250.0060.01215.18
7.2.240.0070.01214.96
7.2.230.0050.00915.12
7.2.220.0080.00814.98
7.2.210.0090.00315.08
7.2.200.0070.00814.99
7.2.190.0110.00614.97
7.2.180.0080.00715.01
7.2.170.0060.01115.05
7.2.160.0110.00614.90
7.2.150.0080.00815.89
7.2.140.0050.01115.80
7.2.130.0050.00916.04
7.2.120.0090.01015.79
7.2.110.0110.00415.95
7.2.100.0080.01115.85
7.2.90.0100.00915.98
7.2.80.0110.00815.92
7.2.70.0100.01015.98
7.2.60.0090.00816.30
7.2.50.0060.01416.14
7.2.40.0130.00916.07
7.2.30.0090.01116.01
7.2.20.0140.00716.02
7.2.10.0080.01116.01
7.2.00.0100.00717.15
7.1.330.0080.01115.14
7.1.320.0100.00715.26
7.1.310.0080.00815.27
7.1.300.0090.00715.26
7.1.290.0120.00315.16
7.1.280.0100.00714.98
7.1.270.0060.00815.24
7.1.260.0070.00815.14
7.1.250.0090.00714.96
7.1.240.0080.01014.87
7.1.230.0110.00714.81
7.1.220.0080.01214.85
7.1.210.0130.00714.90
7.1.200.0140.00915.07
7.1.190.0230.00514.77
7.1.180.0120.00814.87
7.1.170.0160.00414.89
7.1.160.0080.01114.70
7.1.150.0100.00915.00
7.1.140.0130.00714.77
7.1.130.0090.00714.81
7.1.120.0110.00914.77
7.1.110.0070.01314.93
7.1.100.0210.00715.98
7.1.90.0090.00614.87
7.1.80.0110.00614.94
7.1.70.0070.00715.56
7.1.60.0100.01116.32
7.1.50.0080.01115.63
7.1.40.0110.00914.97
7.1.30.0090.00914.96
7.1.20.0140.00514.93
7.1.10.0110.00814.66
7.1.00.0060.03117.43
7.0.330.0040.01114.49
7.0.320.0080.01114.38
7.0.310.0150.00514.55
7.0.300.0110.00814.43
7.0.290.0130.00714.51
7.0.280.0070.00714.41
7.0.270.0080.00614.37
7.0.260.0090.01014.46
7.0.250.0140.00514.49
7.0.240.0100.01014.33
7.0.230.0120.00514.57
7.0.220.0080.00714.49
7.0.210.0090.00714.63
7.0.200.0110.00614.58
7.0.190.0100.00514.28
7.0.180.0120.00914.59
7.0.170.0090.00914.57
7.0.160.0110.00814.37
7.0.150.0010.01314.62
7.0.140.0060.02117.00
7.0.130.0110.00814.56
7.0.120.0050.01014.46
7.0.110.0120.00414.65
7.0.100.0090.00914.56
7.0.90.0230.00814.48
7.0.80.0100.00814.50
7.0.70.0070.01014.53
7.0.60.0130.02816.26
7.0.50.0050.02115.83
7.0.40.0090.02815.63
7.0.30.0130.03315.68
7.0.20.0150.02615.65
7.0.10.0120.02015.83
7.0.00.0060.02015.71
5.6.400.0130.00914.33
5.6.390.0100.00914.62
5.6.380.0080.01014.37
5.6.370.0100.00814.25
5.6.360.0050.01314.43
5.6.350.0090.01014.59
5.6.340.0100.00714.33
5.6.330.0130.01414.60
5.6.320.0110.00914.59
5.6.310.0100.00914.70
5.6.300.0080.00814.39
5.6.290.0100.00714.66
5.6.280.0070.03016.51
5.6.270.0070.01014.57
5.6.260.0080.00714.47
5.6.250.0070.00914.35
5.6.240.0110.00814.56
5.6.230.0100.00914.63
5.6.220.0100.00614.41
5.6.210.0120.02916.67
5.6.200.0120.01715.78
5.6.190.0050.02116.42
5.6.180.0120.02316.45
5.6.170.0150.02816.49
5.6.160.0080.02916.49
5.6.150.0080.02915.76
5.6.140.0050.03615.75
5.6.130.0070.03415.74
5.6.120.0050.02116.64
5.6.110.0070.03716.68
5.6.100.0090.01816.55
5.6.90.0110.02516.64
5.6.80.0080.02616.54
5.6.70.0180.03016.46
5.6.60.0090.00914.31
5.6.50.0050.01314.21
5.6.40.0090.00614.30
5.6.30.0100.01114.34
5.6.20.0130.00314.26
5.6.10.0100.00614.42
5.6.00.0150.00414.37
5.5.380.0090.00914.39
5.5.370.0070.01414.55
5.5.360.0110.00614.35
5.5.350.0120.01516.50
5.5.340.0070.03415.70
5.5.330.0140.02916.38
5.5.320.0150.02816.31
5.5.310.0200.03016.46
5.5.300.0090.03115.46
5.5.290.0050.02815.57
5.5.280.0060.01916.50
5.5.270.0130.03016.41
5.5.260.0090.02316.47
5.5.250.0070.02416.44
5.5.240.0070.01916.35
5.5.230.0090.01114.43
5.5.220.0090.00814.48
5.5.210.0090.00614.34
5.5.200.0100.00914.28
5.5.190.0130.00614.57
5.5.180.0070.01114.11
5.5.170.0080.01014.54
5.5.160.0070.00914.32
5.5.150.0080.01014.45
5.5.140.0110.00614.25
5.5.130.0110.00814.32
5.5.120.0050.01414.00
5.5.110.0070.01014.23
5.5.100.0130.00914.37
5.5.90.0090.00914.28
5.5.80.0120.00414.43
5.5.70.0050.01414.37
5.5.60.0070.01014.30
5.5.50.0060.00914.25
5.5.40.0070.01014.23
5.5.30.0100.00614.56
5.5.20.0070.01014.36
5.5.10.0110.00814.63
5.5.00.0130.00414.35
5.4.450.0160.02214.67
5.4.440.0360.02314.72
5.4.430.0130.02014.71
5.4.420.0300.02114.74
5.4.410.0100.02114.54
5.4.400.0490.02214.35
5.4.390.0450.02214.38
5.4.380.0440.02114.44
5.4.370.0500.02114.38
5.4.360.0530.01814.45
5.4.350.0400.02414.45
5.4.340.0460.01714.37
5.4.330.0080.00912.27
5.4.320.0430.02314.45
5.4.310.0450.02314.43
5.4.300.0350.02214.43
5.4.290.0490.02014.46
5.4.280.0280.02514.43
5.4.270.0120.02514.38
5.4.260.0340.02514.42
5.4.250.0610.03214.38
5.4.240.0580.02814.41
5.4.230.0570.02614.38
5.4.220.0590.02514.38
5.4.210.0530.02314.43
5.4.200.0460.02313.72
5.4.190.0510.02514.43
5.4.180.0630.02914.36
5.4.170.0530.02814.45
5.4.160.0400.02214.43
5.4.150.0400.02114.34
5.4.140.0440.01913.68
5.4.130.0410.02213.61
5.4.120.0440.02013.63
5.4.110.0470.02013.62
5.4.100.0450.02113.61
5.4.90.0510.02113.64
5.4.80.0490.01813.67
5.4.70.0480.02013.62
5.4.60.0490.01813.63
5.4.50.0410.02013.63
5.4.40.0450.02513.59
5.4.30.0430.02013.61
5.4.20.0510.02113.58
5.4.10.0370.02013.61
5.4.00.0440.01813.49
5.3.290.0610.02713.72
5.3.280.0650.03313.75
5.3.270.0700.03313.75
5.3.260.0670.03313.72
5.3.250.0650.02913.70
5.3.240.0710.03613.70
5.3.230.0650.03013.75
5.3.220.0510.03313.75
5.3.210.0550.03113.71
5.3.200.0670.03213.68
5.3.190.0560.03213.67
5.3.180.0600.03313.74
5.3.170.0680.03013.64
5.3.160.0510.03313.66
5.3.150.0780.02513.70
5.3.140.0680.03113.66
5.3.130.0670.03013.66
5.3.120.0640.03013.74
5.3.110.0790.03013.70
5.3.100.0690.03113.49
5.3.90.0570.02513.48
5.3.80.0630.02813.37
5.3.70.0770.01713.39
5.3.60.0710.02613.47
5.3.50.0560.03113.35
5.3.40.0880.03213.43
5.3.30.0650.02413.34
5.3.20.0570.02513.25
5.3.10.0940.02213.31
5.3.00.0550.03213.24
5.2.170.1710.01912.05
5.2.160.0590.02211.96
5.2.150.0480.02811.97
5.2.140.0560.02511.96
5.2.130.0760.01011.99
5.2.120.0580.03011.98
5.2.110.0590.03011.93
5.2.100.0580.03611.98
5.2.90.0580.03311.96
5.2.80.0700.02811.98
5.2.70.0660.02612.03
5.2.60.0690.03011.89
5.2.50.0690.03011.91
5.2.40.0590.02411.93
5.2.30.0560.02711.96
5.2.20.0540.02711.96
5.2.10.0440.02411.86
5.2.00.0450.02211.76
5.1.60.0460.02111.39
5.1.50.0400.02511.41
5.1.40.0540.02211.38
5.1.30.0500.02711.64
5.1.20.0400.02511.57
5.1.10.0140.01911.50
5.1.00.0130.02011.43
5.0.50.0030.02410.67
5.0.40.0180.02010.59
5.0.30.0430.03010.46
5.0.20.0270.01710.47
5.0.10.0280.02010.51
5.0.00.0270.03010.54
4.4.90.0310.0159.32
4.4.80.0210.0149.30
4.4.70.0250.0129.32
4.4.60.0230.0129.35
4.4.50.0240.0109.32
4.4.40.0270.0189.31
4.4.30.0190.0149.32
4.4.20.0240.0169.32
4.4.10.0200.0129.33
4.4.00.0220.0179.36
4.3.110.0170.0149.27
4.3.100.0230.0099.27
4.3.90.0180.0139.28
4.3.80.0260.0189.27
4.3.70.0260.0139.27
4.3.60.0200.0139.25
4.3.50.0220.0139.26
4.3.40.0240.0179.25
4.3.30.0100.0158.64
4.3.20.0110.0188.62
4.3.10.0120.0158.62
4.3.00.0050.0149.79

preferences:
44.46 ms | 400 KiB | 5 Q