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