3v4l.org

run code in 300+ PHP versions simultaneously
<?php fgets(STDIN); $numbers = explode(' ', rtrim(fgets(STDIN))); $valuePerWife = array_sum($numbers) / 2; // Taken from here: http://stackoverflow.com/a/13194803/603003 // Credits to dAngelov: http://stackoverflow.com/users/955185/dangelov function pc_permute($items, $perms = array( )) { if (empty($items)) { $return = array($perms); } else { $return = array(); for ($i = count($items) - 1; $i >= 0; --$i) { $newitems = $items; $newperms = $perms; list($foo) = array_splice($newitems, $i, 1); array_unshift($newperms, $foo); $return = array_merge($return, pc_permute($newitems, $newperms)); } } return $return; } foreach (pc_permute($numbers) as $permutation) { $sum = 0; $rest = []; for ($i=0; $i<count($permutation); $i++) { $sum += $permutation[$i]; if ($sum == $valuePerWife) { $rest = array_slice($permutation, $i + 1); break; } } if (array_sum($rest) == $valuePerWife) { echo implode(' ', array_slice($permutation, 0, $i + 1)), "\n"; echo implode(' ', array_slice($permutation, $i + 1)), "\n"; echo 'diff=0'; exit; } } exit('DIDNT FOUND ANY COMBINATION!');
Output for 8.3.0 - 8.3.7
Warning: array_sum(): Addition is not supported on type string in /in/tMTs7 on line 4 Fatal error: Uncaught TypeError: Unsupported operand types: int + string in /in/tMTs7:30 Stack trace: #0 {main} thrown in /in/tMTs7 on line 30
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19
Fatal error: Uncaught TypeError: Unsupported operand types: int + string in /in/tMTs7:30 Stack trace: #0 {main} thrown in /in/tMTs7 on line 30
Process exited with code 255.
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Warning: A non-numeric value encountered in /in/tMTs7 on line 30 diff=0
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33
diff=0
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/tMTs7 on line 27
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/tMTs7 on line 27
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/tMTs7 on line 27
Process exited with code 255.

preferences:
279.09 ms | 401 KiB | 462 Q