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!');
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 76
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 76
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 30
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 75
Branch analysis from position: 50
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 75
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 41
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 30
Branch analysis from position: 45
Branch analysis from position: 30
Branch analysis from position: 76
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 76
filename:       /in/tMTs7
function name:  (null)
number of ops:  79
compiled vars:  !0 = $numbers, !1 = $valuePerWife, !2 = $permutation, !3 = $sum, !4 = $rest, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'fgets'
          1        FETCH_CONSTANT                                   ~6      'STDIN'
          2        SEND_VAL                                                 ~6
          3        DO_ICALL                                                 
    3     4        INIT_FCALL                                               'explode'
          5        SEND_VAL                                                 '+'
          6        INIT_FCALL                                               'rtrim'
          7        INIT_FCALL                                               'fgets'
          8        FETCH_CONSTANT                                   ~8      'STDIN'
          9        SEND_VAL                                                 ~8
         10        DO_ICALL                                         $9      
         11        SEND_VAR                                                 $9
         12        DO_ICALL                                         $10     
         13        SEND_VAR                                                 $10
         14        DO_ICALL                                         $11     
         15        ASSIGN                                                   !0, $11
    4    16        INIT_FCALL                                               'array_sum'
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                         $13     
         19        DIV                                              ~14     $13, 2
         20        ASSIGN                                                   !1, ~14
   25    21        INIT_FCALL                                               'pc_permute'
         22        SEND_VAR                                                 !0
         23        DO_FCALL                                      0  $16     
         24      > FE_RESET_R                                       $17     $16, ->76
         25    > > FE_FETCH_R                                               $17, !2, ->76
   26    26    >   ASSIGN                                                   !3, 0
   27    27        ASSIGN                                                   !4, <array>
   29    28        ASSIGN                                                   !5, 0
         29      > JMP                                                      ->42
   30    30    >   FETCH_DIM_R                                      ~21     !2, !5
         31        ASSIGN_OP                                     1          !3, ~21
   31    32        IS_EQUAL                                                 !3, !1
         33      > JMPZ                                                     ~23, ->41
   32    34    >   INIT_FCALL                                               'array_slice'
         35        SEND_VAR                                                 !2
         36        ADD                                              ~24     !5, 1
         37        SEND_VAL                                                 ~24
         38        DO_ICALL                                         $25     
         39        ASSIGN                                                   !4, $25
   33    40      > JMP                                                      ->45
   29    41    >   PRE_INC                                                  !5
         42    >   COUNT                                            ~28     !2
         43        IS_SMALLER                                               !5, ~28
         44      > JMPNZ                                                    ~29, ->30
   37    45    >   INIT_FCALL                                               'array_sum'
         46        SEND_VAR                                                 !4
         47        DO_ICALL                                         $30     
         48        IS_EQUAL                                                 !1, $30
         49      > JMPZ                                                     ~31, ->75
   38    50    >   INIT_FCALL                                               'implode'
         51        SEND_VAL                                                 '+'
         52        INIT_FCALL                                               'array_slice'
         53        SEND_VAR                                                 !2
         54        SEND_VAL                                                 0
         55        ADD                                              ~32     !5, 1
         56        SEND_VAL                                                 ~32
         57        DO_ICALL                                         $33     
         58        SEND_VAR                                                 $33
         59        DO_ICALL                                         $34     
         60        ECHO                                                     $34
         61        ECHO                                                     '%0A'
   39    62        INIT_FCALL                                               'implode'
         63        SEND_VAL                                                 '+'
         64        INIT_FCALL                                               'array_slice'
         65        SEND_VAR                                                 !2
         66        ADD                                              ~35     !5, 1
         67        SEND_VAL                                                 ~35
         68        DO_ICALL                                         $36     
         69        SEND_VAR                                                 $36
         70        DO_ICALL                                         $37     
         71        ECHO                                                     $37
         72        ECHO                                                     '%0A'
   40    73        ECHO                                                     'diff%3D0'
   41    74      > EXIT                                                     
   25    75    > > JMP                                                      ->25
         76    >   FE_FREE                                                  $17
   44    77      > EXIT                                                     'DIDNT+FOUND+ANY+COMBINATION%21'
         78*     > RETURN                                                   1

Function pc_permute:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 12
Branch analysis from position: 38
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 12
Branch analysis from position: 38
Branch analysis from position: 12
filename:       /in/tMTs7
function name:  pc_permute
number of ops:  40
compiled vars:  !0 = $items, !1 = $perms, !2 = $return, !3 = $i, !4 = $newitems, !5 = $newperms, !6 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
    9     2        ISSET_ISEMPTY_CV                                         !0
          3      > JMPZ                                                     ~7, ->7
   10     4    >   INIT_ARRAY                                       ~8      !1
          5        ASSIGN                                                   !2, ~8
          6      > JMP                                                      ->38
   12     7    >   ASSIGN                                                   !2, <array>
   13     8        COUNT                                            ~11     !0
          9        SUB                                              ~12     ~11, 1
         10        ASSIGN                                                   !3, ~12
         11      > JMP                                                      ->36
   14    12    >   ASSIGN                                                   !4, !0
   15    13        ASSIGN                                                   !5, !1
   16    14        INIT_FCALL                                               'array_splice'
         15        SEND_REF                                                 !4
         16        SEND_VAR                                                 !3
         17        SEND_VAL                                                 1
         18        DO_ICALL                                         $16     
         19        FETCH_LIST_R                                     $17     $16, 0
         20        ASSIGN                                                   !6, $17
         21        FREE                                                     $16
   17    22        INIT_FCALL                                               'array_unshift'
         23        SEND_REF                                                 !5
         24        SEND_VAR                                                 !6
         25        DO_ICALL                                                 
   18    26        INIT_FCALL                                               'array_merge'
         27        SEND_VAR                                                 !2
         28        INIT_FCALL_BY_NAME                                       'pc_permute'
         29        SEND_VAR_EX                                              !4
         30        SEND_VAR_EX                                              !5
         31        DO_FCALL                                      0  $20     
         32        SEND_VAR                                                 $20
         33        DO_ICALL                                         $21     
         34        ASSIGN                                                   !2, $21
   13    35        PRE_DEC                                                  !3
         36    >   IS_SMALLER_OR_EQUAL                                      0, !3
         37      > JMPNZ                                                    ~24, ->12
   21    38    > > RETURN                                                   !2
   22    39*     > RETURN                                                   null

End of function pc_permute

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.23 ms | 1411 KiB | 32 Q