3v4l.org

run code in 300+ PHP versions simultaneously
<?php $answer = 1; // The Setup settype($answer, 'integer'); $s = (string) $a = &$answer; $ns = (string) $n = (isset($s[1])) ? ($a >> 1)+$s[1] : ($a >> 1)+$s[0]; $f = ((int) $ns[0] ^ (int) $s[1]); // The Riddle function riddle($a, $n, $s, $f, $ns) { if ( ($a != 0 && luhn($a)) && (!$f) && (($n | $a) == 63) && (!isset($s[2])) ) { return TRUE; } return FALSE; } // The Result if (riddle($a, $n, $s, $f, $ns)) { echo "You got the correct answer! ($a)"; } else { echo "Sorry, wrong answer. ($a)"; } function luhn($number) { settype($number, 'string'); $sumTable = array( array(0,1,2,3,4,5,6,7,8,9), array(0,2,4,6,8,1,3,5,7,9)); $sum = 0; $flip = 0; for ($i = strlen($number) - 1; $i >= 0; $i--) { $sum += $sumTable[$flip++ & 0x1][$number[$i]]; } return $sum % 10 === 0; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 41
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 41
Branch analysis from position: 36
Branch analysis from position: 41
filename:       /in/TPo86
function name:  (null)
number of ops:  46
compiled vars:  !0 = $answer, !1 = $s, !2 = $a, !3 = $ns, !4 = $n, !5 = $f
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, 1
    8     1        INIT_FCALL                                               'settype'
          2        SEND_REF                                                 !0
          3        SEND_VAL                                                 'integer'
          4        DO_ICALL                                                 
    9     5        ASSIGN_REF                                       $8      !2, !0
          6        CAST                                          6  ~9      $8
          7        ASSIGN                                                   !1, ~9
   10     8        ISSET_ISEMPTY_DIM_OBJ                         0          !1, 1
          9      > JMPZ                                                     ~11, ->15
         10    >   SR                                               ~12     !2, 1
         11        FETCH_DIM_R                                      ~13     !1, 1
         12        ADD                                              ~14     ~12, ~13
         13        QM_ASSIGN                                        ~15     ~14
         14      > JMP                                                      ->19
         15    >   SR                                               ~16     !2, 1
         16        FETCH_DIM_R                                      ~17     !1, 0
         17        ADD                                              ~18     ~16, ~17
         18        QM_ASSIGN                                        ~15     ~18
         19    >   ASSIGN                                           ~19     !4, ~15
         20        CAST                                          6  ~20     ~19
         21        ASSIGN                                                   !3, ~20
   11    22        FETCH_DIM_R                                      ~22     !3, 0
         23        CAST                                          4  ~23     ~22
         24        FETCH_DIM_R                                      ~24     !1, 1
         25        CAST                                          4  ~25     ~24
         26        BW_XOR                                           ~26     ~23, ~25
         27        ASSIGN                                                   !5, ~26
   27    28        INIT_FCALL                                               'riddle'
         29        SEND_VAR                                                 !2
         30        SEND_VAR                                                 !4
         31        SEND_VAR                                                 !1
         32        SEND_VAR                                                 !5
         33        SEND_VAR                                                 !3
         34        DO_FCALL                                      0  $28     
         35      > JMPZ                                                     $28, ->41
   28    36    >   ROPE_INIT                                     3  ~30     'You+got+the+correct+answer%21+%28'
         37        ROPE_ADD                                      1  ~30     ~30, !2
         38        ROPE_END                                      2  ~29     ~30, '%29'
         39        ECHO                                                     ~29
         40      > JMP                                                      ->45
   30    41    >   ROPE_INIT                                     3  ~33     'Sorry%2C+wrong+answer.+%28'
         42        ROPE_ADD                                      1  ~33     ~33, !2
         43        ROPE_END                                      2  ~32     ~33, '%29'
         44        ECHO                                                     ~32
   49    45    > > RETURN                                                   1

Function riddle:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
2 jumps found. (Code = 46) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
2 jumps found. (Code = 46) Position 1 = 15, Position 2 = 18
Branch analysis from position: 15
2 jumps found. (Code = 46) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 24
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
Branch analysis from position: 18
Branch analysis from position: 14
Branch analysis from position: 11
filename:       /in/TPo86
function name:  riddle
number of ops:  26
compiled vars:  !0 = $a, !1 = $n, !2 = $s, !3 = $f, !4 = $ns
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        RECV                                             !4      
   16     5        IS_NOT_EQUAL                                     ~5      !0, 0
          6      > JMPZ_EX                                          ~5      ~5, ->11
          7    >   INIT_FCALL_BY_NAME                                       'luhn'
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0  $6      
         10        BOOL                                             ~5      $6
         11    > > JMPZ_EX                                          ~5      ~5, ->14
   17    12    >   BOOL_NOT                                         ~7      !3
         13        BOOL                                             ~5      ~7
         14    > > JMPZ_EX                                          ~5      ~5, ->18
   18    15    >   BW_OR                                            ~8      !1, !0
         16        IS_EQUAL                                         ~9      ~8, 63
         17        BOOL                                             ~5      ~9
         18    > > JMPZ_EX                                          ~5      ~5, ->22
   19    19    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~10     !2, 2
         20        BOOL_NOT                                         ~11     ~10
         21        BOOL                                             ~5      ~11
         22    > > JMPZ                                                     ~5, ->24
   21    23    > > RETURN                                                   <true>
   23    24    > > RETURN                                                   <false>
   24    25*     > RETURN                                                   null

End of function riddle

Function luhn:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 12
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 12
Branch analysis from position: 21
Branch analysis from position: 12
filename:       /in/TPo86
function name:  luhn
number of ops:  25
compiled vars:  !0 = $number, !1 = $sumTable, !2 = $sum, !3 = $flip, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   39     1        INIT_FCALL                                               'settype'
          2        SEND_REF                                                 !0
          3        SEND_VAL                                                 'string'
          4        DO_ICALL                                                 
   40     5        ASSIGN                                                   !1, <array>
   43     6        ASSIGN                                                   !2, 0
   44     7        ASSIGN                                                   !3, 0
   45     8        STRLEN                                           ~9      !0
          9        SUB                                              ~10     ~9, 1
         10        ASSIGN                                                   !4, ~10
         11      > JMP                                                      ->19
   46    12    >   POST_INC                                         ~12     !3
         13        BW_AND                                           ~13     ~12, 1
         14        FETCH_DIM_R                                      ~15     !0, !4
         15        FETCH_DIM_R                                      ~14     !1, ~13
         16        FETCH_DIM_R                                      ~16     ~14, ~15
         17        ASSIGN_OP                                     1          !2, ~16
   45    18        PRE_DEC                                                  !4
         19    >   IS_SMALLER_OR_EQUAL                                      0, !4
         20      > JMPNZ                                                    ~19, ->12
   48    21    >   MOD                                              ~20     !2, 10
         22        IS_IDENTICAL                                     ~21     ~20, 0
         23      > RETURN                                                   ~21
   49    24*     > RETURN                                                   null

End of function luhn

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.51 ms | 1398 KiB | 16 Q