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) { $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; } } if ($ok) { 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 = 87
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 87
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 85
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 85
Branch analysis from position: 25
2 jumps found. (Code = 77) Position 1 = 32, Position 2 = 69
Branch analysis from position: 32
2 jumps found. (Code = 78) Position 1 = 33, Position 2 = 69
Branch analysis from position: 33
5 jumps found. (Code = 188) Position 1 = 54, Position 2 = 57, Position 3 = 60, Position 4 = 63, Position 5 = 47
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 68
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 85
Branch analysis from position: 85
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 68
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
Branch analysis from position: 63
Branch analysis from position: 47
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 54
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 51, Position 2 = 57
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 60
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
Branch analysis from position: 60
Branch analysis from position: 57
Branch analysis from position: 54
Branch analysis from position: 69
2 jumps found. (Code = 43) Position 1 = 71, Position 2 = 84
Branch analysis from position: 71
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 84
Branch analysis from position: 69
Branch analysis from position: 85
Branch analysis from position: 85
Branch analysis from position: 87
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 87
filename:       /in/LQ8jS
function name:  (null)
number of ops:  89
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, ->87
          3    > > FE_FETCH_R                                               $16, !2, ->87
   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, ->85
         24    > > FE_FETCH_R                                               $25, !6, ->85
   36    25    >   INIT_FCALL                                               'explode'
         26        SEND_VAL                                                 '%2C'
         27        SEND_VAR                                                 !6
         28        DO_ICALL                                         $26     
         29        ASSIGN                                                   !7, $26
   38    30        ASSIGN                                                   !8, <array>
   39    31      > FE_RESET_R                                       $29     !7, ->69
         32    > > FE_FETCH_R                                               $29, !9, ->69
   41    33    >   INIT_FCALL                                               'explode'
         34        SEND_VAL                                                 '+'
         35        INIT_FCALL                                               'trim'
         36        SEND_VAR                                                 !9
         37        DO_ICALL                                         $30     
         38        SEND_VAR                                                 $30
         39        DO_ICALL                                         $31     
         40        ASSIGN                                                   !10, $31
   42    41        FETCH_DIM_R                                      ~33     !10, 0
         42        CAST                                          4  ~34     ~33
         43        ASSIGN                                                   !11, ~34
   43    44        FETCH_DIM_R                                      ~36     !10, 1
         45        ASSIGN                                                   !12, ~36
   45    46      > SWITCH_STRING                                            !12, [ 'red':->54, 'green':->57, 'blue':->60, ], ->63
   47    47    >   IS_EQUAL                                                 !12, 'red'
         48      > JMPNZ                                                    ~38, ->54
   50    49    >   IS_EQUAL                                                 !12, 'green'
         50      > JMPNZ                                                    ~38, ->57
   53    51    >   IS_EQUAL                                                 !12, 'blue'
         52      > JMPNZ                                                    ~38, ->60
         53    > > JMP                                                      ->63
   48    54    >   ASSIGN_DIM_OP                +=               1          !8, 0
         55        OP_DATA                                                  !11
   49    56      > JMP                                                      ->63
   51    57    >   ASSIGN_DIM_OP                +=               1          !8, 1
         58        OP_DATA                                                  !11
   52    59      > JMP                                                      ->63
   54    60    >   ASSIGN_DIM_OP                +=               1          !8, 2
         61        OP_DATA                                                  !11
   55    62      > JMP                                                      ->63
   59    63    >   IS_SMALLER                                               !1, !8
         64      > JMPZ                                                     ~42, ->68
   62    65    >   ASSIGN                                                   !5, <false>
   63    66        FE_FREE                                                  $29
         67      > JMP                                                      ->85
   39    68    > > JMP                                                      ->32
         69    >   FE_FREE                                                  $29
   67    70      > JMPZ                                                     !5, ->84
   69    71    >   INIT_FCALL                                               'preg_match'
         72        SEND_VAL                                                 '%2F%5Cd%2B%2F'
         73        INIT_FCALL                                               'substr'
         74        SEND_VAR                                                 !2
         75        SEND_VAL                                                 0
         76        SEND_VAR                                                 !3
         77        DO_ICALL                                         $44     
         78        SEND_VAR                                                 $44
         79        SEND_REF                                                 !13
         80        DO_ICALL                                                 
   70    81        INIT_FCALL                                               'var_dump'
         82        SEND_VAR                                                 !13
         83        DO_ICALL                                                 
   34    84    > > JMP                                                      ->24
         85    >   FE_FREE                                                  $25
   27    86      > JMP                                                      ->3
         87    >   FE_FREE                                                  $16
   74    88      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.69 ms | 1441 KiB | 19 Q