3v4l.org

run code in 300+ PHP versions simultaneously
<?php function matrix_brute_solve(array $matrix) { matrix_make_square($matrix); foreach (matrix_generate_vectors($matrix) as $vector) { $attempt = matrix_rotate($matrix, $vector); if (matrix_is_solved($attempt)) return matrix_display($attempt); } echo 'No solution'; } function matrix_make_square(array &$matrix) { $pad = count(array_keys($matrix)); foreach ($matrix as &$row) $row = array_pad($row, $pad, ''); } function matrix_generate_vectors(array $matrix) { $vectors = []; $columns = count(current($matrix)); $gen = function ($depth=0, $combo='') use (&$gen, &$vectors, $columns) { if ($depth < $columns) for ($i = 0; $i < $columns; $i++) $gen($depth + 1, $i . $combo); else $vectors[] = array_map('intval', str_split($combo)); }; $gen(); return $vectors; } function matrix_rotate(array $matrix, array $vector) { foreach ($matrix as $row => &$values) { array_rotate($values, $vector[$row]); } return $matrix; } function matrix_is_solved(array $matrix) { foreach (array_keys(current($matrix)) as $offset) { $column = array_filter($raw = array_column($matrix, $offset)); if (count($column) != count(array_unique($column))) return false; } return true; } function array_rotate(array &$array, $offset) { foreach (array_slice($array, 0, $offset) as $key => $val) { unset($array[$key]); $array[$key] = $val; } $array = array_values($array); } function matrix_display(array $matrix = null) { echo "[\n"; foreach ($matrix as $row => $inner) { echo " $row => ['" . implode("', '", $inner) . "']\n"; } echo "]\n"; } $tests = [ [ ['X'], ['X'] ], [ ['X'], ['X'], ['X'] ], [ [ 'X', '' ], [ '', 'X' ] ], [ ['X', 'Y', 'Z'], ['X', 'Y'], ['X']], [ ['X', 'Y'], ['X', 'Y'], ['X', 'Y'] ], [ ['X', 'Y', 'Z'], ['X', 'Y', 'Z'], ['X', 'Y', 'Z'] ], [ ['X', 'Y', 'Z', 'I', 'J'], ['X', 'Y', 'Z', 'I'], ['X', 'Y', 'Z', 'I'], ['X', 'Y', 'Z', 'I'], ['X', 'Y', 'Z'], ['X', 'Y', 'Z'] ], ]; array_map(function ($matrix) { matrix_display($matrix); echo "solved by:" . PHP_EOL; matrix_brute_solve($matrix); echo PHP_EOL; }, $tests);

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.0200.04727.38
8.3.50.0210.04827.14
8.3.40.0270.05529.31
8.3.30.0230.03729.35
8.3.20.0250.01330.84
8.3.10.0070.02133.54
8.3.00.0030.02333.64
8.2.180.0100.04827.36
8.2.170.0260.03929.51
8.2.160.0260.04230.77
8.2.150.0100.04229.75
8.2.140.0070.02731.09
8.2.130.0300.02330.85
8.2.120.0070.02131.22
8.2.110.0130.03731.02
8.2.100.0220.03228.18
8.2.90.0000.04528.25
8.2.80.0030.04129.37
8.2.70.0030.04128.00
8.2.60.0030.04028.13
8.2.50.0070.04028.47
8.2.40.0070.03728.37
8.2.30.0070.03730.08
8.2.20.0130.02928.55
8.2.10.0140.03128.52
8.2.00.0030.04028.54
8.1.280.0360.04636.29
8.1.270.0130.03340.19
8.1.260.0140.01836.09
8.1.250.0150.01838.71
8.1.240.0200.03740.61
8.1.230.0140.04140.57
8.1.220.0090.03835.48
8.1.210.0140.03535.61
8.1.200.0070.04035.73
8.1.190.0170.03335.60
8.1.180.0110.03635.36
8.1.170.0190.03236.66
8.1.160.0100.03637.07
8.1.150.0100.03537.36
8.1.140.0130.03335.96
8.1.130.0100.04037.09
8.1.120.0070.04635.76
8.1.110.0100.03935.76
8.1.100.0100.03835.73
8.1.90.0200.04035.70
8.1.80.0170.03435.77
8.1.70.0140.03535.75
8.1.60.0170.03435.89
8.1.50.0000.05235.70
8.1.40.0170.03535.79
8.1.30.0070.04735.78
8.1.20.0160.04535.80
8.1.10.0130.03535.86
8.1.00.0100.04135.78
8.0.300.0140.04535.25
8.0.290.0100.03834.88
8.0.280.0030.04336.31
8.0.270.0070.04034.70
8.0.260.0200.03634.77
8.0.250.0030.04335.08
8.0.240.0060.04134.97
8.0.230.0130.03635.18
8.0.220.0030.05435.08
8.0.210.0130.03335.12
8.0.200.0070.04335.17
8.0.190.0230.03335.18
8.0.180.0130.04035.04
8.0.170.0130.03535.02
8.0.160.0170.03635.12
8.0.150.0100.04435.00
8.0.140.0100.04135.09
8.0.130.0100.04031.52
8.0.120.0070.04434.96
8.0.110.0070.04334.88
8.0.100.0160.03334.96
8.0.90.0100.04035.11
8.0.80.0330.10335.09
8.0.70.0100.03934.93
8.0.60.0060.04235.14
8.0.50.0290.01935.06
8.0.30.0230.07035.18
8.0.20.0230.08235.20
8.0.10.0100.03935.18
8.0.00.0220.07334.82
7.4.330.0030.03434.66
7.4.320.0060.03834.60
7.4.300.0070.03934.59
7.4.290.0030.04434.69
7.4.280.0130.03934.72
7.4.270.0240.02734.53
7.4.260.0170.03734.59
7.4.250.0000.04834.50
7.4.240.0030.04534.64
7.4.230.0100.03734.58
7.4.220.0990.07734.61
7.4.210.0160.07334.66
7.4.200.0130.03634.76
7.4.160.0180.06934.62
7.4.150.0210.07134.60
7.4.140.0260.06934.59
7.4.130.0500.08734.60
7.4.120.0280.07534.63
7.4.110.0100.11834.70
7.4.100.0230.12034.72
7.4.90.0310.06934.55
7.4.80.0260.12034.70
7.4.70.0210.07534.74
7.4.60.0160.07434.71
7.4.50.0200.05634.45
7.4.40.0280.06234.48
7.4.30.0260.07134.69
7.4.00.0100.07532.83
7.3.330.0100.04031.41
7.3.320.0070.04231.44
7.3.310.0100.03834.34
7.3.300.0030.04434.43
7.3.290.0280.05834.49
7.3.280.0220.08734.48
7.3.270.0370.05834.65
7.3.260.0290.07834.63
7.3.250.0330.08134.50
7.3.240.0230.09034.55
7.3.230.0350.06134.63
7.3.210.0200.07034.68
7.3.200.0160.09034.44
7.3.190.0300.06034.46
7.3.180.0300.05834.50
7.3.170.0190.07134.47
7.3.160.0230.07234.47
7.3.10.0380.06034.65
7.3.00.0240.06934.65
7.2.330.0360.06934.73
7.2.320.0380.10834.61
7.2.310.0420.06634.90
7.2.300.0300.07635.02
7.2.290.0290.07534.74
7.2.130.0320.06134.62
7.2.120.0340.06434.92
7.2.110.0300.07534.61
7.2.100.0290.06235.03
7.2.90.0380.07934.79
7.2.80.0490.06434.86
7.2.70.0160.07835.08
7.2.60.0810.07034.51
7.2.50.0390.06434.83
7.2.40.0310.08934.71
7.2.30.0290.07934.39
7.2.20.0300.07434.45
7.2.10.0490.06234.85
7.2.00.0420.07034.96
7.1.250.0420.09333.91
7.1.200.0560.05633.86
7.1.110.0860.08035.39
7.1.100.1370.09935.42
7.1.90.1420.11635.37
7.1.80.1240.11235.24
7.1.70.1380.10234.40
7.1.60.1630.09852.44
7.1.50.1490.08652.30
7.1.40.1740.10651.93
7.1.30.1470.11351.81
7.1.20.0290.08052.69
7.1.10.0100.12434.59
7.1.00.0160.09434.78
7.0.250.0730.09335.00
7.0.240.1320.11034.82
7.0.230.1600.13435.18
7.0.220.1510.12735.16
7.0.210.1480.10233.90
7.0.200.1430.09234.08
7.0.190.1360.09834.02
7.0.180.1260.10033.68
7.0.170.0940.07733.97
7.0.160.0090.11634.27
7.0.150.0150.11434.21
7.0.140.0090.10434.49
7.0.130.0160.09634.58
7.0.120.0210.08534.66
7.0.110.0850.12434.40
7.0.100.0100.09534.33
7.0.90.0100.08134.50
7.0.80.0080.13234.44
7.0.70.0130.13534.37
7.0.60.0150.09234.18
7.0.50.0680.08733.76
7.0.40.0160.10534.75
7.0.30.0140.12334.60
7.0.20.0130.07934.40
7.0.10.0120.11934.53
7.0.00.0140.11534.49

preferences:
71.52 ms | 400 KiB | 5 Q