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}/",$input, $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($input)===1){ $lights[$j][$k] = 1; } else if(action($input)===2){ $lights[$j][$k] = 0; } else if(action($input)===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 = 93
Branch analysis from position: 93
2 jumps found. (Code = 44) Position 1 = 95, Position 2 = 53
Branch analysis from position: 95
1 jumps found. (Code = 42) Position 1 = 109
Branch analysis from position: 109
2 jumps found. (Code = 44) Position 1 = 111, Position 2 = 98
Branch analysis from position: 111
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 98
1 jumps found. (Code = 42) Position 1 = 106
Branch analysis from position: 106
2 jumps found. (Code = 44) Position 1 = 108, Position 2 = 100
Branch analysis from position: 108
2 jumps found. (Code = 44) Position 1 = 111, Position 2 = 98
Branch analysis from position: 111
Branch analysis from position: 98
Branch analysis from position: 100
2 jumps found. (Code = 43) Position 1 = 104, Position 2 = 105
Branch analysis from position: 104
2 jumps found. (Code = 44) Position 1 = 108, Position 2 = 100
Branch analysis from position: 108
Branch analysis from position: 100
Branch analysis from position: 105
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 90
Branch analysis from position: 90
2 jumps found. (Code = 44) Position 1 = 92, Position 2 = 55
Branch analysis from position: 92
2 jumps found. (Code = 44) Position 1 = 95, Position 2 = 53
Branch analysis from position: 95
Branch analysis from position: 53
Branch analysis from position: 55
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 64
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 89
Branch analysis from position: 89
2 jumps found. (Code = 44) Position 1 = 92, Position 2 = 55
Branch analysis from position: 92
Branch analysis from position: 55
Branch analysis from position: 64
2 jumps found. (Code = 43) Position 1 = 69, Position 2 = 73
Branch analysis from position: 69
1 jumps found. (Code = 42) Position 1 = 89
Branch analysis from position: 89
Branch analysis from position: 73
2 jumps found. (Code = 43) Position 1 = 78, Position 2 = 89
Branch analysis from position: 78
2 jumps found. (Code = 43) Position 1 = 82, Position 2 = 86
Branch analysis from position: 82
1 jumps found. (Code = 42) Position 1 = 89
Branch analysis from position: 89
Branch analysis from position: 86
2 jumps found. (Code = 44) Position 1 = 92, Position 2 = 55
Branch analysis from position: 92
Branch analysis from position: 55
Branch analysis from position: 89
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/ND3tQ
function name:  (null)
number of ops:  113
compiled vars:  !0 = $input, !1 = $lights, !2 = $i, !3 = $j, !4 = $matches, !5 = $from, !6 = $to, !7 = $x1, !8 = $y1, !9 = $x2, !10 = $y2, !11 = $k, !12 = $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                                      $17     !1, !2
          7        ASSIGN_DIM                                               $17, !3
          8        OP_DATA                                                  0
    7     9        PRE_INC                                                  !3
         10    >   IS_SMALLER                                               !3, 1000
         11      > JMPNZ                                                    ~20, ->6
    6    12    >   PRE_INC                                                  !2
         13    >   IS_SMALLER                                               !2, 1000
         14      > JMPNZ                                                    ~22, ->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        SEND_VAR                                                 !0
         19        SEND_REF                                                 !4
         20        DO_ICALL                                                 
   32    21        FETCH_DIM_R                                      ~25     !4, 0
         22        FETCH_DIM_R                                      ~26     ~25, 0
         23        ASSIGN                                                   !5, ~26
   33    24        FETCH_DIM_R                                      ~28     !4, 0
         25        FETCH_DIM_R                                      ~29     ~28, 1
         26        ASSIGN                                                   !6, ~29
   34    27        INIT_FCALL                                               'explode'
         28        SEND_VAL                                                 '%2C'
         29        SEND_VAR                                                 !5
         30        DO_ICALL                                         $31     
         31        FETCH_DIM_R                                      ~32     $31, 0
         32        ASSIGN                                                   !7, ~32
   35    33        INIT_FCALL                                               'explode'
         34        SEND_VAL                                                 '%2C'
         35        SEND_VAR                                                 !5
         36        DO_ICALL                                         $34     
         37        FETCH_DIM_R                                      ~35     $34, 0
         38        ASSIGN                                                   !8, ~35
   36    39        INIT_FCALL                                               'explode'
         40        SEND_VAL                                                 '%2C'
         41        SEND_VAR                                                 !6
         42        DO_ICALL                                         $37     
         43        FETCH_DIM_R                                      ~38     $37, 0
         44        ASSIGN                                                   !9, ~38
   37    45        INIT_FCALL                                               'explode'
         46        SEND_VAL                                                 '%2C'
         47        SEND_VAR                                                 !6
         48        DO_ICALL                                         $40     
         49        FETCH_DIM_R                                      ~41     $40, 1
         50        ASSIGN                                                   !10, ~41
   38    51        ASSIGN                                                   !3, !8
         52      > JMP                                                      ->93
   39    53    >   ASSIGN                                                   !11, !7
         54      > JMP                                                      ->90
   40    55    >   INIT_FCALL                                               'action'
         56        SEND_VAR                                                 !0
         57        DO_FCALL                                      0  $45     
         58        IS_IDENTICAL                                             $45, 1
         59      > JMPZ                                                     ~46, ->64
   41    60    >   FETCH_DIM_W                                      $47     !1, !3
         61        ASSIGN_DIM                                               $47, !11
         62        OP_DATA                                                  1
         63      > JMP                                                      ->89
   43    64    >   INIT_FCALL                                               'action'
         65        SEND_VAR                                                 !0
         66        DO_FCALL                                      0  $49     
         67        IS_IDENTICAL                                             $49, 2
         68      > JMPZ                                                     ~50, ->73
   44    69    >   FETCH_DIM_W                                      $51     !1, !3
         70        ASSIGN_DIM                                               $51, !11
         71        OP_DATA                                                  0
         72      > JMP                                                      ->89
   46    73    >   INIT_FCALL                                               'action'
         74        SEND_VAR                                                 !0
         75        DO_FCALL                                      0  $53     
         76        IS_IDENTICAL                                             $53, 3
         77      > JMPZ                                                     ~54, ->89
   47    78    >   FETCH_DIM_R                                      ~55     !1, !3
         79        FETCH_DIM_R                                      ~56     ~55, !11
         80        IS_IDENTICAL                                             ~56, 0
         81      > JMPZ                                                     ~57, ->86
   48    82    >   FETCH_DIM_W                                      $58     !1, !3
         83        ASSIGN_DIM                                               $58, !11
         84        OP_DATA                                                  1
         85      > JMP                                                      ->89
   51    86    >   FETCH_DIM_W                                      $60     !1, !3
         87        ASSIGN_DIM                                               $60, !11
         88        OP_DATA                                                  0
   39    89    >   PRE_INC                                                  !11
         90    >   IS_SMALLER_OR_EQUAL                                      !11, !9
         91      > JMPNZ                                                    ~63, ->55
   38    92    >   PRE_INC                                                  !3
         93    >   IS_SMALLER_OR_EQUAL                                      !3, !10
         94      > JMPNZ                                                    ~65, ->53
   57    95    >   ASSIGN                                                   !12, 0
   58    96        ASSIGN                                                   !2, 0
         97      > JMP                                                      ->109
   59    98    >   ASSIGN                                                   !3, 0
         99      > JMP                                                      ->106
   60   100    >   FETCH_DIM_R                                      ~69     !1, !2
        101        FETCH_DIM_R                                      ~70     ~69, !3
        102        IS_IDENTICAL                                             ~70, 1
        103      > JMPZ                                                     ~71, ->105
   61   104    >   PRE_INC                                                  !12
   59   105    >   PRE_INC                                                  !3
        106    >   IS_SMALLER                                               !3, 1000
        107      > JMPNZ                                                    ~74, ->100
   58   108    >   PRE_INC                                                  !2
        109    >   IS_SMALLER                                               !2, 1000
        110      > JMPNZ                                                    ~76, ->98
   66   111    >   ECHO                                                     !12
   68   112      > 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/ND3tQ
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:
154.73 ms | 1411 KiB | 22 Q