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 = $i+1; $j < $nb; $j++){ 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/MKQjl
function name:  (null)
number of ops:  17
compiled vars:  !0 = $try, !1 = $find, !2 = $r
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E > > FE_RESET_R                                       $3      <array>, ->15
          1    > > FE_FETCH_R                                       ~4      $3, !0, ->15
          2    >   ASSIGN                                                   !1, ~4
   34     3        INIT_FCALL                                               'comparecombinations'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $6      
          7        ASSIGN                                                   !2, $6
   35     8        INIT_FCALL                                               'var_dump'
   36     9        INIT_ARRAY                                       ~8      !1, 'find'
   37    10        ADD_ARRAY_ELEMENT                                ~8      !0, 'try'
   38    11        ADD                                              ~9      ~8, !2
         12        SEND_VAL                                                 ~9
         13        DO_ICALL                                                 
   33    14      > JMP                                                      ->1
         15    >   FE_FREE                                                  $3
   39    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 = 37
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 25
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 28
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 25
Branch analysis from position: 39
Branch analysis from position: 25
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 33
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 28
Branch analysis from position: 36
Branch analysis from position: 28
Branch analysis from position: 33
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/MKQjl
function name:  compareCombinations
number of ops:  46
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                                                      ->37
   19    25    >   ADD                                              ~22     !5, 1
         26        ASSIGN                                                   !6, ~22
         27      > JMP                                                      ->34
   20    28    >   FETCH_DIM_R                                      ~24     !0, !5
         29        FETCH_DIM_R                                      ~25     !1, !6
         30        IS_IDENTICAL                                             ~24, ~25
         31      > JMPZ                                                     ~26, ->33
   21    32    >   PRE_INC                                                  !4
   19    33    >   PRE_INC                                                  !6
         34    >   IS_SMALLER                                               !6, !2
         35      > JMPNZ                                                    ~29, ->28
   18    36    >   PRE_INC                                                  !5
         37    >   IS_SMALLER                                               !5, !2
         38      > JMPNZ                                                    ~31, ->25
   27    39    >   INIT_ARRAY                                       ~32     !3, 'good'
   28    40        ADD_ARRAY_ELEMENT                                ~32     !4, 'wrong'
   29    41        SUB                                              ~33     !2, !3
         42        SUB                                              ~34     ~33, !4
         43        ADD_ARRAY_ELEMENT                                ~32     ~34, 'absent'
         44      > RETURN                                                   ~32
   31    45*     > RETURN                                                   null

End of function comparecombinations

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.03 ms | 1403 KiB | 18 Q