3v4l.org

run code in 300+ PHP versions simultaneously
<?php // //$maxRed = 12; //$maxGreen = 13; //$maxBlue = 14; // //$lines = file($_SERVER["DOCUMENT_ROOT"]."/input2.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $lines = [ 'Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green', 'Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue', 'Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red', 'Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red', 'Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green', ]; //$limits = [ // 'red' => 12, // 'green' => 13, // 'blue' => 14, //]; $limits = [12, 13, 14]; foreach ($lines as $game) { $colonPos = strpos($game, ':'); $sets = explode(';', trim(substr($game, $colonPos + 1))); $ok = true; foreach ($sets as $set) { if (!$ok) { break; } $picks = explode(',', $set); $pickSum = [0,0,0]; foreach ($picks as $pick) { $pickArray = explode(' ', trim($pick)); $attempt = (int)$pickArray[0]; $color = $pickArray[1]; switch($color) { case 'red': $pickSum[0] += $attempt; break; case 'green': $pickSum[1] += $attempt; break; case 'blue': $pickSum[2] += $attempt; break; } // var_dump($pickSum); if ($limits < $pickSum) { // var_dump('11'); $ok = false; break 2; } } preg_match('/\d+/', substr($game, 0, $colonPos), $matches); var_dump($matches); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 89
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 89
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 87
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 87
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 28
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 87
Branch analysis from position: 87
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 28
2 jumps found. (Code = 77) Position 1 = 35, Position 2 = 72
Branch analysis from position: 35
2 jumps found. (Code = 78) Position 1 = 36, Position 2 = 72
Branch analysis from position: 36
5 jumps found. (Code = 188) Position 1 = 57, Position 2 = 60, Position 3 = 63, Position 4 = 66, Position 5 = 50
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 66
Branch analysis from position: 66
2 jumps found. (Code = 43) Position 1 = 68, Position 2 = 71
Branch analysis from position: 68
1 jumps found. (Code = 42) Position 1 = 87
Branch analysis from position: 87
Branch analysis from position: 71
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 66
Branch analysis from position: 66
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 66
Branch analysis from position: 66
Branch analysis from position: 66
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 57
Branch analysis from position: 52
2 jumps found. (Code = 44) Position 1 = 54, Position 2 = 60
Branch analysis from position: 54
2 jumps found. (Code = 44) Position 1 = 56, Position 2 = 63
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 66
Branch analysis from position: 66
Branch analysis from position: 63
Branch analysis from position: 60
Branch analysis from position: 57
Branch analysis from position: 72
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 72
Branch analysis from position: 87
Branch analysis from position: 87
Branch analysis from position: 89
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 89
filename:       /in/ktlBY
function name:  (null)
number of ops:  91
compiled vars:  !0 = $lines, !1 = $limits, !2 = $game, !3 = $colonPos, !4 = $sets, !5 = $ok, !6 = $set, !7 = $picks, !8 = $pickSum, !9 = $pick, !10 = $pickArray, !11 = $attempt, !12 = $color, !13 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   ASSIGN                                                   !0, <array>
   24     1        ASSIGN                                                   !1, <array>
   27     2      > FE_RESET_R                                       $16     !0, ->89
          3    > > FE_FETCH_R                                               $16, !2, ->89
   29     4    >   INIT_FCALL                                               'strpos'
          5        SEND_VAR                                                 !2
          6        SEND_VAL                                                 '%3A'
          7        DO_ICALL                                         $17     
          8        ASSIGN                                                   !3, $17
   31     9        INIT_FCALL                                               'explode'
         10        SEND_VAL                                                 '%3B'
         11        INIT_FCALL                                               'trim'
         12        INIT_FCALL                                               'substr'
         13        SEND_VAR                                                 !2
         14        ADD                                              ~19     !3, 1
         15        SEND_VAL                                                 ~19
         16        DO_ICALL                                         $20     
         17        SEND_VAR                                                 $20
         18        DO_ICALL                                         $21     
         19        SEND_VAR                                                 $21
         20        DO_ICALL                                         $22     
         21        ASSIGN                                                   !4, $22
   32    22        ASSIGN                                                   !5, <true>
   34    23      > FE_RESET_R                                       $25     !4, ->87
         24    > > FE_FETCH_R                                               $25, !6, ->87
   36    25    >   BOOL_NOT                                         ~26     !5
         26      > JMPZ                                                     ~26, ->28
   38    27    > > JMP                                                      ->87
   41    28    >   INIT_FCALL                                               'explode'
         29        SEND_VAL                                                 '%2C'
         30        SEND_VAR                                                 !6
         31        DO_ICALL                                         $27     
         32        ASSIGN                                                   !7, $27
   43    33        ASSIGN                                                   !8, <array>
   44    34      > FE_RESET_R                                       $30     !7, ->72
         35    > > FE_FETCH_R                                               $30, !9, ->72
   46    36    >   INIT_FCALL                                               'explode'
         37        SEND_VAL                                                 '+'
         38        INIT_FCALL                                               'trim'
         39        SEND_VAR                                                 !9
         40        DO_ICALL                                         $31     
         41        SEND_VAR                                                 $31
         42        DO_ICALL                                         $32     
         43        ASSIGN                                                   !10, $32
   47    44        FETCH_DIM_R                                      ~34     !10, 0
         45        CAST                                          4  ~35     ~34
         46        ASSIGN                                                   !11, ~35
   48    47        FETCH_DIM_R                                      ~37     !10, 1
         48        ASSIGN                                                   !12, ~37
   50    49      > SWITCH_STRING                                            !12, [ 'red':->57, 'green':->60, 'blue':->63, ], ->66
   52    50    >   IS_EQUAL                                                 !12, 'red'
         51      > JMPNZ                                                    ~39, ->57
   55    52    >   IS_EQUAL                                                 !12, 'green'
         53      > JMPNZ                                                    ~39, ->60
   58    54    >   IS_EQUAL                                                 !12, 'blue'
         55      > JMPNZ                                                    ~39, ->63
         56    > > JMP                                                      ->66
   53    57    >   ASSIGN_DIM_OP                +=               1          !8, 0
         58        OP_DATA                                                  !11
   54    59      > JMP                                                      ->66
   56    60    >   ASSIGN_DIM_OP                +=               1          !8, 1
         61        OP_DATA                                                  !11
   57    62      > JMP                                                      ->66
   59    63    >   ASSIGN_DIM_OP                +=               1          !8, 2
         64        OP_DATA                                                  !11
   60    65      > JMP                                                      ->66
   64    66    >   IS_SMALLER                                               !1, !8
         67      > JMPZ                                                     ~43, ->71
   67    68    >   ASSIGN                                                   !5, <false>
   68    69        FE_FREE                                                  $30
         70      > JMP                                                      ->87
   44    71    > > JMP                                                      ->35
         72    >   FE_FREE                                                  $30
   73    73        INIT_FCALL                                               'preg_match'
         74        SEND_VAL                                                 '%2F%5Cd%2B%2F'
         75        INIT_FCALL                                               'substr'
         76        SEND_VAR                                                 !2
         77        SEND_VAL                                                 0
         78        SEND_VAR                                                 !3
         79        DO_ICALL                                         $45     
         80        SEND_VAR                                                 $45
         81        SEND_REF                                                 !13
         82        DO_ICALL                                                 
   74    83        INIT_FCALL                                               'var_dump'
         84        SEND_VAR                                                 !13
         85        DO_ICALL                                                 
   34    86      > JMP                                                      ->24
         87    >   FE_FREE                                                  $25
   27    88      > JMP                                                      ->3
         89    >   FE_FREE                                                  $16
   77    90      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149 ms | 1441 KiB | 19 Q