3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Start / End range $start = 1; $end = 100; // The two statements below allowed me to suggest which number to remove // I opted to use a file because I thought it was less obvious than passing // another argument. //$remove = is_readable(__DIR__ . '/remove') ? trim(file_get_contents(__DIR__ . '/remove')) : false; //$remove = isset($argv[2]) ? true : false; // Otherwise we simulate which number we have removed $remove = rand($start, $end); $random = isset($argv[1]) ? true : false; // Create the range $list = range($start, $end); // Determine whether the array should be random $random and shuffle($list); // Because $remove is optional (if user defined) we wrap this with an if if($remove) { $key = array_search($remove, $list); // Make sure the key exists otherwise php treat false == 0 // meaning the first element of the array would be removed if the key wasn't found if($key !== false) { unset($list[$key]); } } // Time to search for the number that was removed // I can't remeber whether I'm allowed to use the in_array method, but this loops through the range 1..100 // and determines whether that value exists. $found = false; for($i = $start; $i <= $end; $i++) { if(!in_array($i, $list)) { $found = $i; print $i . " was removed\n"; break; } } if($found == $remove) { print "Successfuly found the missing number\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 46) Position 1 = 19, Position 2 = 23
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 32
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 32
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 48, Position 2 = 35
Branch analysis from position: 48
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 51
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 45
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 48, Position 2 = 35
Branch analysis from position: 48
Branch analysis from position: 35
Branch analysis from position: 32
Branch analysis from position: 32
Branch analysis from position: 23
Branch analysis from position: 11
2 jumps found. (Code = 46) Position 1 = 19, Position 2 = 23
Branch analysis from position: 19
Branch analysis from position: 23
filename:       /in/thoOk
function name:  (null)
number of ops:  52
compiled vars:  !0 = $start, !1 = $end, !2 = $remove, !3 = $random, !4 = $argv, !5 = $list, !6 = $key, !7 = $found, !8 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, 1
    5     1        ASSIGN                                                   !1, 100
   14     2        INIT_FCALL                                               'rand'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $11     
          6        ASSIGN                                                   !2, $11
   15     7        ISSET_ISEMPTY_DIM_OBJ                         0          !4, 1
          8      > JMPZ                                                     ~13, ->11
          9    >   QM_ASSIGN                                        ~14     <true>
         10      > JMP                                                      ->12
         11    >   QM_ASSIGN                                        ~14     <false>
         12    >   ASSIGN                                                   !3, ~14
   18    13        INIT_FCALL                                               'range'
         14        SEND_VAR                                                 !0
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                         $16     
         17        ASSIGN                                                   !5, $16
   21    18      > JMPZ_EX                                          ~18     !3, ->23
         19    >   INIT_FCALL                                               'shuffle'
         20        SEND_REF                                                 !5
         21        DO_ICALL                                         $19     
         22        BOOL                                             ~18     $19
   24    23    > > JMPZ                                                     !2, ->32
   25    24    >   INIT_FCALL                                               'array_search'
         25        SEND_VAR                                                 !2
         26        SEND_VAR                                                 !5
         27        DO_ICALL                                         $20     
         28        ASSIGN                                                   !6, $20
   29    29        TYPE_CHECK                                  1018          !6
         30      > JMPZ                                                     ~22, ->32
   30    31    >   UNSET_DIM                                                !5, !6
   37    32    >   ASSIGN                                                   !7, <false>
   39    33        ASSIGN                                                   !8, !0
         34      > JMP                                                      ->46
   40    35    >   INIT_FCALL                                               'in_array'
         36        SEND_VAR                                                 !8
         37        SEND_VAR                                                 !5
         38        DO_ICALL                                         $25     
         39        BOOL_NOT                                         ~26     $25
         40      > JMPZ                                                     ~26, ->45
   41    41    >   ASSIGN                                                   !7, !8
   42    42        CONCAT                                           ~28     !8, '+was+removed%0A'
         43        ECHO                                                     ~28
         44      > JMP                                                      ->48
   39    45    >   PRE_INC                                                  !8
         46    >   IS_SMALLER_OR_EQUAL                                      !8, !1
         47      > JMPNZ                                                    ~30, ->35
   46    48    >   IS_EQUAL                                                 !7, !2
         49      > JMPZ                                                     ~31, ->51
   47    50    >   ECHO                                                     'Successfuly+found+the+missing+number%0A'
   48    51    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.28 ms | 1436 KiB | 18 Q