3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = "turn off 499,499 through 500,500"; $lights = [[]]; for($i = 0; $i<1000; $i++){ for($j = 0; $j<1000; $j++){ $lights[$i][$j] = 0; } } //$inputs = explode("\n",$input); function action($s){ $on = preg_match("/turn on/",$s); $off = preg_match("/turn off/",$s); $toggle = preg_match("/toggle/",$s); if($on > 0){ return 1; } else if($off>0){ return 2; } else if($toggle>0){ return 3; } } //for($i = 0; $i < count($inputs); $i++){ $matches = null; preg_match_all("/\d{1,3},\d{1,3}/",$inputs[$i], $matches); $from = $matches[0][0]; $to = $matches[0][1]; $x1 = explode(",",$from)[0]; $y1 = explode(",",$from)[0]; $x2 = explode(",",$to)[0]; $y2 = explode(",",$to)[1]; for($j = $y1; $j<=$y2; $j++){ for($k = $x1; $k<=$x2; $k++){ if(action($inputs[$i])===1){ $lights[$j][$k] = 1; } else if(action($inputs[$i])===2){ $lights[$j][$k] = 0; } else if(action($inputs[$i])===3){ if($lights[$j][$k] === 0){ $lights[$j][$k] = 1; } else{ $lights[$j][$k] = 0; } } } } //} $count = 0; for($i = 0; $i<1000; $i++){ for($j = 0; $j<1000; $j++){ if($lights[$i][$j] === 1){ $count++; } } } echo $count; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 4
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 97
Branch analysis from position: 97
2 jumps found. (Code = 44) Position 1 = 99, Position 2 = 54
Branch analysis from position: 99
1 jumps found. (Code = 42) Position 1 = 113
Branch analysis from position: 113
2 jumps found. (Code = 44) Position 1 = 115, Position 2 = 102
Branch analysis from position: 115
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 102
1 jumps found. (Code = 42) Position 1 = 110
Branch analysis from position: 110
2 jumps found. (Code = 44) Position 1 = 112, Position 2 = 104
Branch analysis from position: 112
2 jumps found. (Code = 44) Position 1 = 115, Position 2 = 102
Branch analysis from position: 115
Branch analysis from position: 102
Branch analysis from position: 104
2 jumps found. (Code = 43) Position 1 = 108, Position 2 = 109
Branch analysis from position: 108
2 jumps found. (Code = 44) Position 1 = 112, Position 2 = 104
Branch analysis from position: 112
Branch analysis from position: 104
Branch analysis from position: 109
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 94
Branch analysis from position: 94
2 jumps found. (Code = 44) Position 1 = 96, Position 2 = 56
Branch analysis from position: 96
2 jumps found. (Code = 44) Position 1 = 99, Position 2 = 54
Branch analysis from position: 99
Branch analysis from position: 54
Branch analysis from position: 56
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 66
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 93
Branch analysis from position: 93
2 jumps found. (Code = 44) Position 1 = 96, Position 2 = 56
Branch analysis from position: 96
Branch analysis from position: 56
Branch analysis from position: 66
2 jumps found. (Code = 43) Position 1 = 72, Position 2 = 76
Branch analysis from position: 72
1 jumps found. (Code = 42) Position 1 = 93
Branch analysis from position: 93
Branch analysis from position: 76
2 jumps found. (Code = 43) Position 1 = 82, Position 2 = 93
Branch analysis from position: 82
2 jumps found. (Code = 43) Position 1 = 86, Position 2 = 90
Branch analysis from position: 86
1 jumps found. (Code = 42) Position 1 = 93
Branch analysis from position: 93
Branch analysis from position: 90
2 jumps found. (Code = 44) Position 1 = 96, Position 2 = 56
Branch analysis from position: 96
Branch analysis from position: 56
Branch analysis from position: 93
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 = 12, Position 2 = 6
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 4
Branch analysis from position: 15
Branch analysis from position: 4
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 6
Branch analysis from position: 12
Branch analysis from position: 6
filename:       /in/TW0gU
function name:  (null)
number of ops:  117
compiled vars:  !0 = $input, !1 = $lights, !2 = $i, !3 = $j, !4 = $matches, !5 = $inputs, !6 = $from, !7 = $to, !8 = $x1, !9 = $y1, !10 = $x2, !11 = $y2, !12 = $k, !13 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'turn+off+499%2C499+through+500%2C500'
    4     1        ASSIGN                                                   !1, <array>
    6     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->13
    7     4    >   ASSIGN                                                   !3, 0
          5      > JMP                                                      ->10
    8     6    >   FETCH_DIM_W                                      $18     !1, !2
          7        ASSIGN_DIM                                               $18, !3
          8        OP_DATA                                                  0
    7     9        PRE_INC                                                  !3
         10    >   IS_SMALLER                                               !3, 1000
         11      > JMPNZ                                                    ~21, ->6
    6    12    >   PRE_INC                                                  !2
         13    >   IS_SMALLER                                               !2, 1000
         14      > JMPNZ                                                    ~23, ->4
   30    15    >   ASSIGN                                                   !4, null
   31    16        INIT_FCALL                                               'preg_match_all'
         17        SEND_VAL                                                 '%2F%5Cd%7B1%2C3%7D%2C%5Cd%7B1%2C3%7D%2F'
         18        FETCH_DIM_R                                      ~25     !5, !2
         19        SEND_VAL                                                 ~25
         20        SEND_REF                                                 !4
         21        DO_ICALL                                                 
   32    22        FETCH_DIM_R                                      ~27     !4, 0
         23        FETCH_DIM_R                                      ~28     ~27, 0
         24        ASSIGN                                                   !6, ~28
   33    25        FETCH_DIM_R                                      ~30     !4, 0
         26        FETCH_DIM_R                                      ~31     ~30, 1
         27        ASSIGN                                                   !7, ~31
   34    28        INIT_FCALL                                               'explode'
         29        SEND_VAL                                                 '%2C'
         30        SEND_VAR                                                 !6
         31        DO_ICALL                                         $33     
         32        FETCH_DIM_R                                      ~34     $33, 0
         33        ASSIGN                                                   !8, ~34
   35    34        INIT_FCALL                                               'explode'
         35        SEND_VAL                                                 '%2C'
         36        SEND_VAR                                                 !6
         37        DO_ICALL                                         $36     
         38        FETCH_DIM_R                                      ~37     $36, 0
         39        ASSIGN                                                   !9, ~37
   36    40        INIT_FCALL                                               'explode'
         41        SEND_VAL                                                 '%2C'
         42        SEND_VAR                                                 !7
         43        DO_ICALL                                         $39     
         44        FETCH_DIM_R                                      ~40     $39, 0
         45        ASSIGN                                                   !10, ~40
   37    46        INIT_FCALL                                               'explode'
         47        SEND_VAL                                                 '%2C'
         48        SEND_VAR                                                 !7
         49        DO_ICALL                                         $42     
         50        FETCH_DIM_R                                      ~43     $42, 1
         51        ASSIGN                                                   !11, ~43
   38    52        ASSIGN                                                   !3, !9
         53      > JMP                                                      ->97
   39    54    >   ASSIGN                                                   !12, !8
         55      > JMP                                                      ->94
   40    56    >   INIT_FCALL                                               'action'
         57        FETCH_DIM_R                                      ~47     !5, !2
         58        SEND_VAL                                                 ~47
         59        DO_FCALL                                      0  $48     
         60        IS_IDENTICAL                                             $48, 1
         61      > JMPZ                                                     ~49, ->66
   41    62    >   FETCH_DIM_W                                      $50     !1, !3
         63        ASSIGN_DIM                                               $50, !12
         64        OP_DATA                                                  1
         65      > JMP                                                      ->93
   43    66    >   INIT_FCALL                                               'action'
         67        FETCH_DIM_R                                      ~52     !5, !2
         68        SEND_VAL                                                 ~52
         69        DO_FCALL                                      0  $53     
         70        IS_IDENTICAL                                             $53, 2
         71      > JMPZ                                                     ~54, ->76
   44    72    >   FETCH_DIM_W                                      $55     !1, !3
         73        ASSIGN_DIM                                               $55, !12
         74        OP_DATA                                                  0
         75      > JMP                                                      ->93
   46    76    >   INIT_FCALL                                               'action'
         77        FETCH_DIM_R                                      ~57     !5, !2
         78        SEND_VAL                                                 ~57
         79        DO_FCALL                                      0  $58     
         80        IS_IDENTICAL                                             $58, 3
         81      > JMPZ                                                     ~59, ->93
   47    82    >   FETCH_DIM_R                                      ~60     !1, !3
         83        FETCH_DIM_R                                      ~61     ~60, !12
         84        IS_IDENTICAL                                             ~61, 0
         85      > JMPZ                                                     ~62, ->90
   48    86    >   FETCH_DIM_W                                      $63     !1, !3
         87        ASSIGN_DIM                                               $63, !12
         88        OP_DATA                                                  1
         89      > JMP                                                      ->93
   51    90    >   FETCH_DIM_W                                      $65     !1, !3
         91        ASSIGN_DIM                                               $65, !12
         92        OP_DATA                                                  0
   39    93    >   PRE_INC                                                  !12
         94    >   IS_SMALLER_OR_EQUAL                                      !12, !10
         95      > JMPNZ                                                    ~68, ->56
   38    96    >   PRE_INC                                                  !3
         97    >   IS_SMALLER_OR_EQUAL                                      !3, !11
         98      > JMPNZ                                                    ~70, ->54
   57    99    >   ASSIGN                                                   !13, 0
   58   100        ASSIGN                                                   !2, 0
        101      > JMP                                                      ->113
   59   102    >   ASSIGN                                                   !3, 0
        103      > JMP                                                      ->110
   60   104    >   FETCH_DIM_R                                      ~74     !1, !2
        105        FETCH_DIM_R                                      ~75     ~74, !3
        106        IS_IDENTICAL                                             ~75, 1
        107      > JMPZ                                                     ~76, ->109
   61   108    >   PRE_INC                                                  !13
   59   109    >   PRE_INC                                                  !3
        110    >   IS_SMALLER                                               !3, 1000
        111      > JMPNZ                                                    ~79, ->104
   58   112    >   PRE_INC                                                  !2
        113    >   IS_SMALLER                                               !2, 1000
        114      > JMPNZ                                                    ~81, ->102
   66   115    >   ECHO                                                     !13
   68   116      > RETURN                                                   1

Function action:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 27
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TW0gU
function name:  action
number of ops:  28
compiled vars:  !0 = $s, !1 = $on, !2 = $off, !3 = $toggle
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%2Fturn+on%2F'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !1, $4
   16     6        INIT_FCALL                                               'preg_match'
          7        SEND_VAL                                                 '%2Fturn+off%2F'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $6      
         10        ASSIGN                                                   !2, $6
   17    11        INIT_FCALL                                               'preg_match'
         12        SEND_VAL                                                 '%2Ftoggle%2F'
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $8      
         15        ASSIGN                                                   !3, $8
   18    16        IS_SMALLER                                               0, !1
         17      > JMPZ                                                     ~10, ->20
   19    18    > > RETURN                                                   1
         19*       JMP                                                      ->27
   21    20    >   IS_SMALLER                                               0, !2
         21      > JMPZ                                                     ~11, ->24
   22    22    > > RETURN                                                   2
         23*       JMP                                                      ->27
   24    24    >   IS_SMALLER                                               0, !3
         25      > JMPZ                                                     ~12, ->27
   25    26    > > RETURN                                                   3
   27    27    > > RETURN                                                   null

End of function action

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.76 ms | 1415 KiB | 22 Q