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 (0 && 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/rcakO
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 = 60
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
2 jumps found. (Code = 46) Position 1 = 57, Position 2 = 59
Branch analysis from position: 57
2 jumps found. (Code = 44) Position 1 = 60, Position 2 = 16
Branch analysis from position: 60
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 50
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 42
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
Branch analysis from position: 50
2 jumps found. (Code = 46) Position 1 = 57, Position 2 = 59
Branch analysis from position: 57
Branch analysis from position: 59
Branch analysis from position: 59
Branch analysis from position: 60
filename:       /in/rcakO
function name:  solution
number of ops:  62
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, ->60
    8     6    > > JMPZ                                                     <false>, ->10
    9     7    >   SUB                                              ~10     !2, 1
          8        ASSIGN                                                   !1, ~10
          9      > JMP                                                      ->60
   11    10    >   INIT_FCALL                                               'round'
         11        DIV                                              ~12     !2, 2
         12        SEND_VAL                                                 ~12
         13        DO_ICALL                                         $13     
         14        ASSIGN                                                   !3, $13
   12    15      > JMP                                                      ->55
   13    16    >   INIT_FCALL                                               'array_slice'
         17        SEND_VAR                                                 !0
         18        SEND_VAL                                                 0
         19        SEND_VAR                                                 !3
         20        DO_ICALL                                         $15     
         21        ASSIGN                                                   !4, $15
   14    22        INIT_FCALL                                               'array_slice'
         23        SEND_VAR                                                 !0
         24        SEND_VAR                                                 !3
         25        DO_ICALL                                         $17     
         26        ASSIGN                                                   !5, $17
   15    27        INIT_FCALL                                               'max'
         28        SEND_VAR                                                 !4
         29        DO_ICALL                                         $19     
         30        FETCH_DIM_R                                      ~20     !0, !3
         31        IS_SMALLER_OR_EQUAL                                      $19, ~20
         32      > JMPZ                                                     ~21, ->50
   16    33    >   INIT_FCALL                                               'min'
         34        SEND_VAR                                                 !5
         35        DO_ICALL                                         $22     
         36        FETCH_DIM_R                                      ~23     !0, !3
         37        IS_SMALLER_OR_EQUAL                                      ~23, $22
         38      > JMPZ                                                     ~24, ->42
   17    39    >   ASSIGN                                                   !1, !3
   18    40      > JMP                                                      ->60
         41*       JMP                                                      ->49
   20    42    >   INIT_FCALL                                               'round'
         43        ADD                                              ~26     !3, !2
         44        SUB                                              ~27     ~26, 1
         45        DIV                                              ~28     ~27, 2
         46        SEND_VAL                                                 ~28
         47        DO_ICALL                                         $29     
         48        ASSIGN                                                   !3, $29
         49      > JMP                                                      ->55
   23    50    >   INIT_FCALL                                               'round'
         51        DIV                                              ~31     !3, 2
         52        SEND_VAL                                                 ~31
         53        DO_ICALL                                         $32     
         54        ASSIGN                                                   !3, $32
   12    55    >   IS_SMALLER                                       ~34     1, !3
         56      > JMPZ_EX                                          ~34     ~34, ->59
         57    >   IS_SMALLER                                       ~35     !3, !2
         58        BOOL                                             ~34     ~35
         59    > > JMPNZ                                                    ~34, ->16
   28    60    > > RETURN                                                   !1
   29    61*     > RETURN                                                   null

End of function solution

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.48 ms | 1407 KiB | 24 Q