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); $r = 0; for ($i = 0; $i < $n; $i++) { $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] = 0; $A[3] = 1 ; $A[4] = 0 ; $A[5] = 0; $A[6] = 0; print_r(solution($A));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mB4D4
function name:  (null)
number of ops:  21
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                                                  0
   37     6        ASSIGN_DIM                                               !0, 3
          7        OP_DATA                                                  1
   38     8        ASSIGN_DIM                                               !0, 4
          9        OP_DATA                                                  0
   39    10        ASSIGN_DIM                                               !0, 5
         11        OP_DATA                                                  0
   40    12        ASSIGN_DIM                                               !0, 6
         13        OP_DATA                                                  0
   43    14        INIT_FCALL                                               'print_r'
         15        INIT_FCALL                                               'solution'
         16        SEND_VAR                                                 !0
         17        DO_FCALL                                      0  $8      
         18        SEND_VAR                                                 $8
         19        DO_ICALL                                                 
         20      > 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 = 61
Branch analysis from position: 61
2 jumps found. (Code = 44) Position 1 = 63, Position 2 = 23
Branch analysis from position: 63
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 36
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 34
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 49
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 47
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 63, Position 2 = 23
Branch analysis from position: 63
Branch analysis from position: 23
Branch analysis from position: 47
2 jumps found. (Code = 44) Position 1 = 63, Position 2 = 23
Branch analysis from position: 63
Branch analysis from position: 23
Branch analysis from position: 49
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 49
Branch analysis from position: 39
Branch analysis from position: 49
Branch analysis from position: 36
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/mB4D4
function name:  solution
number of ops:  66
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        SEND_VAR                                                 !2
         19        DO_ICALL                                                 
   11    20        ASSIGN                                                   !4, 0
   12    21        ASSIGN                                                   !3, 0
         22      > JMP                                                      ->61
   13    23    >   ASSIGN                                                   !5, 0
   14    24        IS_SMALLER                                               0, !3
         25      > JMPZ                                                     ~23, ->36
   15    26    >   SUB                                              ~24     !3, 1
         27        FETCH_DIM_R                                      ~25     !0, ~24
         28        FETCH_DIM_R                                      ~26     !0, !3
         29        IS_NOT_EQUAL                                             ~25, ~26
         30      > JMPZ                                                     ~27, ->34
   16    31    >   ADD                                              ~28     !5, 1
         32        ASSIGN                                                   !5, ~28
         33      > JMP                                                      ->36
   18    34    >   SUB                                              ~30     !5, 1
         35        ASSIGN                                                   !5, ~30
   20    36    >   SUB                                              ~32     !1, 1
         37        IS_SMALLER                                               !3, ~32
         38      > JMPZ                                                     ~33, ->49
   21    39    >   ADD                                              ~34     !3, 1
         40        FETCH_DIM_R                                      ~35     !0, ~34
         41        FETCH_DIM_R                                      ~36     !0, !3
         42        IS_NOT_EQUAL                                             ~35, ~36
         43      > JMPZ                                                     ~37, ->47
   22    44    >   ADD                                              ~38     !5, 1
         45        ASSIGN                                                   !5, ~38
         46      > JMP                                                      ->49
   24    47    >   SUB                                              ~40     !5, 1
         48        ASSIGN                                                   !5, ~40
   26    49    >   INIT_FCALL                                               'print_r'
         50        CONCAT                                           ~42     !4, '%21%21%21'
         51        CONCAT                                           ~43     ~42, !5
         52        CONCAT                                           ~44     ~43, '%0A'
         53        SEND_VAL                                                 ~44
         54        DO_ICALL                                                 
   27    55        INIT_FCALL                                               'max'
         56        SEND_VAR                                                 !4
         57        SEND_VAR                                                 !5
         58        DO_ICALL                                         $46     
         59        ASSIGN                                                   !4, $46
   12    60        PRE_INC                                                  !3
         61    >   IS_SMALLER                                               !3, !1
         62      > JMPNZ                                                    ~49, ->23
   30    63    >   ADD                                              ~50     !2, !4
         64      > RETURN                                                   ~50
   31    65*     > RETURN                                                   null

End of function solution

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.08 ms | 1407 KiB | 18 Q