3v4l.org

run code in 300+ PHP versions simultaneously
<?php function compareCombinations($toFind, $toTry){ $nb = 4; $goodPlace = 0; $wrongPlace = 0; $toFind = str_split($toFind); $toTry = str_split($toTry); //Look for good places for($i = 0; $i < $nb; $i++){ if($toFind[$i] === $toTry[$i]){ $goodPlace++; } } //Look for wrong places for($i = 0; $i < $nb; $i++){ for($j = 0; $j < $nb; $j++){ if($i == $j){ continue; } if($toFind[$i] === $toTry[$j]){ $wrongPlace++; } } } return array( 'good' => $goodPlace, 'wrong' => $wrongPlace, 'absent' => $nb - $goodPlace - $wrongPlace ); } foreach(array('0000' => '0001') as $find => $try){ $r = compareCombinations($find,$try); var_dump(array( 'find' => $find, 'try' => $try ) + $r); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 1, Position 2 = 15
Branch analysis from position: 1
2 jumps found. (Code = 78) Position 1 = 2, Position 2 = 15
Branch analysis from position: 2
1 jumps found. (Code = 42) Position 1 = 1
Branch analysis from position: 1
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/EQCtJ
function name:  (null)
number of ops:  17
compiled vars:  !0 = $try, !1 = $find, !2 = $r
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E > > FE_RESET_R                                       $3      <array>, ->15
          1    > > FE_FETCH_R                                       ~4      $3, !0, ->15
          2    >   ASSIGN                                                   !1, ~4
   37     3        INIT_FCALL                                               'comparecombinations'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $6      
          7        ASSIGN                                                   !2, $6
   38     8        INIT_FCALL                                               'var_dump'
   39     9        INIT_ARRAY                                       ~8      !1, 'find'
   40    10        ADD_ARRAY_ELEMENT                                ~8      !0, 'try'
   41    11        ADD                                              ~9      ~8, !2
         12        SEND_VAL                                                 ~9
         13        DO_ICALL                                                 
   36    14      > JMP                                                      ->1
         15    >   FE_FREE                                                  $3
   42    16      > RETURN                                                   1

Function comparecombinations:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 15
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 25
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 27
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 25
Branch analysis from position: 41
Branch analysis from position: 25
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 30
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 27
Branch analysis from position: 38
Branch analysis from position: 27
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 35
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 27
Branch analysis from position: 38
Branch analysis from position: 27
Branch analysis from position: 35
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 15
Branch analysis from position: 23
Branch analysis from position: 15
Branch analysis from position: 20
filename:       /in/EQCtJ
function name:  compareCombinations
number of ops:  48
compiled vars:  !0 = $toFind, !1 = $toTry, !2 = $nb, !3 = $goodPlace, !4 = $wrongPlace, !5 = $i, !6 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    3     2        ASSIGN                                                   !2, 4
    4     3        ASSIGN                                                   !3, 0
    5     4        ASSIGN                                                   !4, 0
    7     5        INIT_FCALL                                               'str_split'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $10     
          8        ASSIGN                                                   !0, $10
    8     9        INIT_FCALL                                               'str_split'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $12     
         12        ASSIGN                                                   !1, $12
   11    13        ASSIGN                                                   !5, 0
         14      > JMP                                                      ->21
   12    15    >   FETCH_DIM_R                                      ~15     !0, !5
         16        FETCH_DIM_R                                      ~16     !1, !5
         17        IS_IDENTICAL                                             ~15, ~16
         18      > JMPZ                                                     ~17, ->20
   13    19    >   PRE_INC                                                  !3
   11    20    >   PRE_INC                                                  !5
         21    >   IS_SMALLER                                               !5, !2
         22      > JMPNZ                                                    ~20, ->15
   18    23    >   ASSIGN                                                   !5, 0
         24      > JMP                                                      ->39
   19    25    >   ASSIGN                                                   !6, 0
         26      > JMP                                                      ->36
   20    27    >   IS_EQUAL                                                 !5, !6
         28      > JMPZ                                                     ~23, ->30
   21    29    > > JMP                                                      ->35
   23    30    >   FETCH_DIM_R                                      ~24     !0, !5
         31        FETCH_DIM_R                                      ~25     !1, !6
         32        IS_IDENTICAL                                             ~24, ~25
         33      > JMPZ                                                     ~26, ->35
   24    34    >   PRE_INC                                                  !4
   19    35    >   PRE_INC                                                  !6
         36    >   IS_SMALLER                                               !6, !2
         37      > JMPNZ                                                    ~29, ->27
   18    38    >   PRE_INC                                                  !5
         39    >   IS_SMALLER                                               !5, !2
         40      > JMPNZ                                                    ~31, ->25
   30    41    >   INIT_ARRAY                                       ~32     !3, 'good'
   31    42        ADD_ARRAY_ELEMENT                                ~32     !4, 'wrong'
   32    43        SUB                                              ~33     !2, !3
         44        SUB                                              ~34     ~33, !4
         45        ADD_ARRAY_ELEMENT                                ~32     ~34, 'absent'
         46      > RETURN                                                   ~32
   34    47*     > RETURN                                                   null

End of function comparecombinations

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.72 ms | 1411 KiB | 18 Q