3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Para testear tu código en nuestros servidores debes mantener la estructura expuesta abajo. // Eres libre de crear nuevas funciones/procedimientos. // Recuerda que el código que escribas podrá ser visto por las empresas a las que te postules. ?> <?php $relieve = [[8, 9, 2, 2, 3, 5], [9, 8, 3, 2, 4, 5], [9, 7, 2, 2, 4, 3], [9, 9, 2, 4, 4, 3], [9, 2, 3, 4, 3, 5]]; var_dump(celdas_vecinas($relieve, 0, 1)); // Representación gráfica // 8 9 2 2 3 5 // 9 8 3 2 4 5 // 9 7 2 2 4 3 // 9 9 2 4 4 3 // 9 2 3 4 3 5 function encontrar_bordes($relieve){ $resp = []; for($i=0;$i<count($relieve);$i++){ for($j=0;$j<count($relieve[$i]);$j++){ $resp[$i][$j] = 0; } } return $resp; // return [[1, 0, 1, 1, 0, 0], [0, 0, 0, 1, 0, 0], [0, 0, 1, 1, 0, 1], [0, 0, 1, 0, 0, 1], [0, 1, 0, 0, 1, 0 ]]; } function celdas_vecinas($relieve, $i, $j){ $celdas = []; // si la celda no existe, regresamos. if(!celda_existe($relieve, $i, $j)){ return null; } if(celda_existe($relieve, $i-1, $j-1)) { $celdas[] = $relieve[$i-1][$j-1]; } if(celda_existe($relieve, $i-1, $j)) { $celdas[] = $relieve[$i-1][$j]; } if(celda_existe($relieve, $i-1, $j+1)) { $celdas[] = $relieve[$i-1][$j+1]; } if(celda_existe($relieve, $i, $j-1)) { $celdas[] = $relieve[$i][$j-1]; } if(celda_existe($relieve, $i, $j+1)) { $celdas[] = $relieve[$i][$j+1]; } if(celda_existe($relieve, $i+1, $j-1)) { $celdas[] = $relieve[$i+1][$j-1]; } if(celda_existe($relieve, $i+1, $j)) { $celdas[] = $relieve[$i+1][$j]; } if(celda_existe($relieve, $i+1, $j+1)) { $celdas[] = $relieve[$i+1][$j+1]; } //devolvemos los valores de las celdas vecinas return $celdas; } // verificar que una celda existe function celda_existe($arreglo, $x, $y){ if(!array_key_exists($x, $arreglo)){ return false; }elseif(!array_key_exists($y, $arreglo[$x])){ return false; }else{ return true; } } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/a1u16
function name:  (null)
number of ops:  10
compiled vars:  !0 = $relieve
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   ASSIGN                                                   !0, <array>
   10     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL_BY_NAME                                       'celdas_vecinas'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAL_EX                                              0
          5        SEND_VAL_EX                                              1
          6        DO_FCALL                                      0  $2      
          7        SEND_VAR                                                 $2
          8        DO_ICALL                                                 
   75     9      > RETURN                                                   1

Function encontrar_bordes:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 4
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 6
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 4
Branch analysis from position: 18
Branch analysis from position: 4
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 6
Branch analysis from position: 14
Branch analysis from position: 6
filename:       /in/a1u16
function name:  encontrar_bordes
number of ops:  20
compiled vars:  !0 = $relieve, !1 = $resp, !2 = $i, !3 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1        ASSIGN                                                   !1, <array>
   19     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->15
   20     4    >   ASSIGN                                                   !3, 0
          5      > JMP                                                      ->10
   21     6    >   FETCH_DIM_W                                      $7      !1, !2
          7        ASSIGN_DIM                                               $7, !3
          8        OP_DATA                                                  0
   20     9        PRE_INC                                                  !3
         10    >   FETCH_DIM_R                                      ~10     !0, !2
         11        COUNT                                            ~11     ~10
         12        IS_SMALLER                                               !3, ~11
         13      > JMPNZ                                                    ~12, ->6
   19    14    >   PRE_INC                                                  !2
         15    >   COUNT                                            ~14     !0
         16        IS_SMALLER                                               !2, ~14
         17      > JMPNZ                                                    ~15, ->4
   24    18    > > RETURN                                                   !1
   26    19*     > RETURN                                                   null

End of function encontrar_bordes

Function celdas_vecinas:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 26
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 38
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 52
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 64
Branch analysis from position: 59
2 jumps found. (Code = 43) Position 1 = 71, Position 2 = 76
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 84, Position 2 = 90
Branch analysis from position: 84
2 jumps found. (Code = 43) Position 1 = 97, Position 2 = 102
Branch analysis from position: 97
2 jumps found. (Code = 43) Position 1 = 110, Position 2 = 116
Branch analysis from position: 110
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 116
Branch analysis from position: 102
Branch analysis from position: 90
Branch analysis from position: 76
Branch analysis from position: 64
Branch analysis from position: 52
Branch analysis from position: 38
Branch analysis from position: 26
filename:       /in/a1u16
function name:  celdas_vecinas
number of ops:  118
compiled vars:  !0 = $relieve, !1 = $i, !2 = $j, !3 = $celdas
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   29     3        ASSIGN                                                   !3, <array>
   32     4        INIT_FCALL_BY_NAME                                       'celda_existe'
          5        SEND_VAR_EX                                              !0
          6        SEND_VAR_EX                                              !1
          7        SEND_VAR_EX                                              !2
          8        DO_FCALL                                      0  $5      
          9        BOOL_NOT                                         ~6      $5
         10      > JMPZ                                                     ~6, ->12
   33    11    > > RETURN                                                   null
   36    12    >   INIT_FCALL_BY_NAME                                       'celda_existe'
         13        SEND_VAR_EX                                              !0
         14        SUB                                              ~7      !1, 1
         15        SEND_VAL_EX                                              ~7
         16        SUB                                              ~8      !2, 1
         17        SEND_VAL_EX                                              ~8
         18        DO_FCALL                                      0  $9      
         19      > JMPZ                                                     $9, ->26
   37    20    >   SUB                                              ~11     !1, 1
         21        SUB                                              ~13     !2, 1
         22        FETCH_DIM_R                                      ~12     !0, ~11
         23        FETCH_DIM_R                                      ~14     ~12, ~13
         24        ASSIGN_DIM                                               !3
         25        OP_DATA                                                  ~14
   39    26    >   INIT_FCALL_BY_NAME                                       'celda_existe'
         27        SEND_VAR_EX                                              !0
         28        SUB                                              ~15     !1, 1
         29        SEND_VAL_EX                                              ~15
         30        SEND_VAR_EX                                              !2
         31        DO_FCALL                                      0  $16     
         32      > JMPZ                                                     $16, ->38
   40    33    >   SUB                                              ~18     !1, 1
         34        FETCH_DIM_R                                      ~19     !0, ~18
         35        FETCH_DIM_R                                      ~20     ~19, !2
         36        ASSIGN_DIM                                               !3
         37        OP_DATA                                                  ~20
   42    38    >   INIT_FCALL_BY_NAME                                       'celda_existe'
         39        SEND_VAR_EX                                              !0
         40        SUB                                              ~21     !1, 1
         41        SEND_VAL_EX                                              ~21
         42        ADD                                              ~22     !2, 1
         43        SEND_VAL_EX                                              ~22
         44        DO_FCALL                                      0  $23     
         45      > JMPZ                                                     $23, ->52
   43    46    >   SUB                                              ~25     !1, 1
         47        ADD                                              ~27     !2, 1
         48        FETCH_DIM_R                                      ~26     !0, ~25
         49        FETCH_DIM_R                                      ~28     ~26, ~27
         50        ASSIGN_DIM                                               !3
         51        OP_DATA                                                  ~28
   45    52    >   INIT_FCALL_BY_NAME                                       'celda_existe'
         53        SEND_VAR_EX                                              !0
         54        SEND_VAR_EX                                              !1
         55        SUB                                              ~29     !2, 1
         56        SEND_VAL_EX                                              ~29
         57        DO_FCALL                                      0  $30     
         58      > JMPZ                                                     $30, ->64
   46    59    >   SUB                                              ~33     !2, 1
         60        FETCH_DIM_R                                      ~32     !0, !1
         61        FETCH_DIM_R                                      ~34     ~32, ~33
         62        ASSIGN_DIM                                               !3
         63        OP_DATA                                                  ~34
   48    64    >   INIT_FCALL_BY_NAME                                       'celda_existe'
         65        SEND_VAR_EX                                              !0
         66        SEND_VAR_EX                                              !1
         67        ADD                                              ~35     !2, 1
         68        SEND_VAL_EX                                              ~35
         69        DO_FCALL                                      0  $36     
         70      > JMPZ                                                     $36, ->76
   49    71    >   ADD                                              ~39     !2, 1
         72        FETCH_DIM_R                                      ~38     !0, !1
         73        FETCH_DIM_R                                      ~40     ~38, ~39
         74        ASSIGN_DIM                                               !3
         75        OP_DATA                                                  ~40
   51    76    >   INIT_FCALL_BY_NAME                                       'celda_existe'
         77        SEND_VAR_EX                                              !0
         78        ADD                                              ~41     !1, 1
         79        SEND_VAL_EX                                              ~41
         80        SUB                                              ~42     !2, 1
         81        SEND_VAL_EX                                              ~42
         82        DO_FCALL                                      0  $43     
         83      > JMPZ                                                     $43, ->90
   52    84    >   ADD                                              ~45     !1, 1
         85        SUB                                              ~47     !2, 1
         86        FETCH_DIM_R                                      ~46     !0, ~45
         87        FETCH_DIM_R                                      ~48     ~46, ~47
         88        ASSIGN_DIM                                               !3
         89        OP_DATA                                                  ~48
   54    90    >   INIT_FCALL_BY_NAME                                       'celda_existe'
         91        SEND_VAR_EX                                              !0
         92        ADD                                              ~49     !1, 1
         93        SEND_VAL_EX                                              ~49
         94        SEND_VAR_EX                                              !2
         95        DO_FCALL                                      0  $50     
         96      > JMPZ                                                     $50, ->102
   55    97    >   ADD                                              ~52     !1, 1
         98        FETCH_DIM_R                                      ~53     !0, ~52
         99        FETCH_DIM_R                                      ~54     ~53, !2
        100        ASSIGN_DIM                                               !3
        101        OP_DATA                                                  ~54
   57   102    >   INIT_FCALL_BY_NAME                                       'celda_existe'
        103        SEND_VAR_EX                                              !0
        104        ADD                                              ~55     !1, 1
        105        SEND_VAL_EX                                              ~55
        106        ADD                                              ~56     !2, 1
        107        SEND_VAL_EX                                              ~56
        108        DO_FCALL                                      0  $57     
        109      > JMPZ                                                     $57, ->116
   58   110    >   ADD                                              ~59     !1, 1
        111        ADD                                              ~61     !2, 1
        112        FETCH_DIM_R                                      ~60     !0, ~59
        113        FETCH_DIM_R                                      ~62     ~60, ~61
        114        ASSIGN_DIM                                               !3
        115        OP_DATA                                                  ~62
   62   116    > > RETURN                                                   !3
   63   117*     > RETURN                                                   null

End of function celdas_vecinas

Function celda_existe:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/a1u16
function name:  celda_existe
number of ops:  16
compiled vars:  !0 = $arreglo, !1 = $x, !2 = $y
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   67     3        ARRAY_KEY_EXISTS                                 ~3      !1, !0
          4        BOOL_NOT                                         ~4      ~3
          5      > JMPZ                                                     ~4, ->8
   68     6    > > RETURN                                                   <false>
          7*       JMP                                                      ->15
   69     8    >   FETCH_DIM_R                                      ~5      !0, !1
          9        ARRAY_KEY_EXISTS                                 ~6      !2, ~5
         10        BOOL_NOT                                         ~7      ~6
         11      > JMPZ                                                     ~7, ->14
   70    12    > > RETURN                                                   <false>
         13*       JMP                                                      ->15
   72    14    > > RETURN                                                   <true>
   74    15*     > RETURN                                                   null

End of function celda_existe

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.26 ms | 1412 KiB | 15 Q