3v4l.org

run code in 300+ PHP versions simultaneously
<?php function solution($A) { $n = sizeof($A); $result = 0; for ($i = 0; $i < $n - 1; $i++) { if ($A[$i] == $A[$i + 1]) $result = $result + 1; } print_r($result."\n"); $r = 0; for ($i = 1; $i < $n; $i=$i+2) { $count = 0; if ($i > 0) { if ($A[$i - 1] != $A[$i]) $count = $count + 1; else $count = $count - 1; } if ($i < $n - 1) { if ($A[$i + 1] != $A[$i]) $count = $count + 1; else $count = $count - 1; } print_r($r.'!!!'.$count."\n"); $r = max($r, $count); } return $result + $r; } $A[0] = 1; $A[1] = 1; $A[2] = 1; print_r(solution($A));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hHt6M
function name:  (null)
number of ops:  13
compiled vars:  !0 = $A
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   ASSIGN_DIM                                               !0, 0
          1        OP_DATA                                                  1
   35     2        ASSIGN_DIM                                               !0, 1
          3        OP_DATA                                                  1
   36     4        ASSIGN_DIM                                               !0, 2
          5        OP_DATA                                                  1
   39     6        INIT_FCALL                                               'print_r'
          7        INIT_FCALL                                               'solution'
          8        SEND_VAR                                                 !0
          9        DO_FCALL                                      0  $4      
         10        SEND_VAR                                                 $4
         11        DO_ICALL                                                 
         12      > RETURN                                                   1

Function solution:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 6
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 24
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 37
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 35
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 50
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 48
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 24
Branch analysis from position: 65
Branch analysis from position: 24
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 24
Branch analysis from position: 65
Branch analysis from position: 24
Branch analysis from position: 50
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 50
Branch analysis from position: 40
Branch analysis from position: 50
Branch analysis from position: 37
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 6
Branch analysis from position: 17
Branch analysis from position: 6
Branch analysis from position: 13
filename:       /in/hHt6M
function name:  solution
number of ops:  68
compiled vars:  !0 = $A, !1 = $n, !2 = $result, !3 = $i, !4 = $r, !5 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        COUNT                                            ~6      !0
          2        ASSIGN                                                   !1, ~6
    5     3        ASSIGN                                                   !2, 0
    6     4        ASSIGN                                                   !3, 0
          5      > JMP                                                      ->14
    7     6    >   FETCH_DIM_R                                      ~10     !0, !3
          7        ADD                                              ~11     !3, 1
          8        FETCH_DIM_R                                      ~12     !0, ~11
          9        IS_EQUAL                                                 ~10, ~12
         10      > JMPZ                                                     ~13, ->13
    8    11    >   ADD                                              ~14     !2, 1
         12        ASSIGN                                                   !2, ~14
    6    13    >   PRE_INC                                                  !3
         14    >   SUB                                              ~17     !1, 1
         15        IS_SMALLER                                               !3, ~17
         16      > JMPNZ                                                    ~18, ->6
   10    17    >   INIT_FCALL                                               'print_r'
         18        CONCAT                                           ~19     !2, '%0A'
         19        SEND_VAL                                                 ~19
         20        DO_ICALL                                                 
   11    21        ASSIGN                                                   !4, 0
   12    22        ASSIGN                                                   !3, 1
         23      > JMP                                                      ->63
   13    24    >   ASSIGN                                                   !5, 0
   14    25        IS_SMALLER                                               0, !3
         26      > JMPZ                                                     ~24, ->37
   15    27    >   SUB                                              ~25     !3, 1
         28        FETCH_DIM_R                                      ~26     !0, ~25
         29        FETCH_DIM_R                                      ~27     !0, !3
         30        IS_NOT_EQUAL                                             ~26, ~27
         31      > JMPZ                                                     ~28, ->35
   16    32    >   ADD                                              ~29     !5, 1
         33        ASSIGN                                                   !5, ~29
         34      > JMP                                                      ->37
   18    35    >   SUB                                              ~31     !5, 1
         36        ASSIGN                                                   !5, ~31
   20    37    >   SUB                                              ~33     !1, 1
         38        IS_SMALLER                                               !3, ~33
         39      > JMPZ                                                     ~34, ->50
   21    40    >   ADD                                              ~35     !3, 1
         41        FETCH_DIM_R                                      ~36     !0, ~35
         42        FETCH_DIM_R                                      ~37     !0, !3
         43        IS_NOT_EQUAL                                             ~36, ~37
         44      > JMPZ                                                     ~38, ->48
   22    45    >   ADD                                              ~39     !5, 1
         46        ASSIGN                                                   !5, ~39
         47      > JMP                                                      ->50
   24    48    >   SUB                                              ~41     !5, 1
         49        ASSIGN                                                   !5, ~41
   26    50    >   INIT_FCALL                                               'print_r'
         51        CONCAT                                           ~43     !4, '%21%21%21'
         52        CONCAT                                           ~44     ~43, !5
         53        CONCAT                                           ~45     ~44, '%0A'
         54        SEND_VAL                                                 ~45
         55        DO_ICALL                                                 
   27    56        INIT_FCALL                                               'max'
         57        SEND_VAR                                                 !4
         58        SEND_VAR                                                 !5
         59        DO_ICALL                                         $47     
         60        ASSIGN                                                   !4, $47
   12    61        ADD                                              ~49     !3, 2
         62        ASSIGN                                                   !3, ~49
         63    >   IS_SMALLER                                               !3, !1
         64      > JMPNZ                                                    ~51, ->24
   30    65    >   ADD                                              ~52     !2, !4
         66      > RETURN                                                   ~52
   31    67*     > RETURN                                                   null

End of function solution

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
189.5 ms | 1398 KiB | 18 Q