3v4l.org

run code in 300+ PHP versions simultaneously
<?php function solution($A) { // write your code in PHP5 $result = -1; $n = count($A); if ($n > 0) { if (max($A) == $A[$n-1]) { $result = $n-1; } else { $center = round($n/2); while($center >1 && $center < $n){ $left = array_slice($A, 0, $center); $right = array_slice($A, $center); if (max($left) <= $A[$center]) { if (min($right) >= $A[$center]) { $result = $center; break; } else { $center = round(($center + $n - 1)/2); } } else { $center = round($center/2); } } } } return $result; } $A[0] = 4 ; $A[1] = 2 ; $A[2] = 2; $A[3] = 3 ; $A[4] = 1 ; $A[5] = 4; $A[6] = 7 ; $A[7] = 8 ; $A[8] = 6; $A[9] = 9; print_r(solution($A));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0tcFd
function name:  (null)
number of ops:  27
compiled vars:  !0 = $A
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   ASSIGN_DIM                                               !0, 0
          1        OP_DATA                                                  4
   34     2        ASSIGN_DIM                                               !0, 1
          3        OP_DATA                                                  2
   35     4        ASSIGN_DIM                                               !0, 2
          5        OP_DATA                                                  2
   36     6        ASSIGN_DIM                                               !0, 3
          7        OP_DATA                                                  3
   37     8        ASSIGN_DIM                                               !0, 4
          9        OP_DATA                                                  1
   38    10        ASSIGN_DIM                                               !0, 5
         11        OP_DATA                                                  4
   39    12        ASSIGN_DIM                                               !0, 6
         13        OP_DATA                                                  7
   40    14        ASSIGN_DIM                                               !0, 7
         15        OP_DATA                                                  8
   41    16        ASSIGN_DIM                                               !0, 8
         17        OP_DATA                                                  6
   42    18        ASSIGN_DIM                                               !0, 9
         19        OP_DATA                                                  9
   44    20        INIT_FCALL                                               'print_r'
         21        INIT_FCALL                                               'solution'
         22        SEND_VAR                                                 !0
         23        DO_FCALL                                      0  $11     
         24        SEND_VAR                                                 $11
         25        DO_ICALL                                                 
         26      > RETURN                                                   1

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

End of function solution

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157 ms | 1407 KiB | 24 Q