3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gdr_encode($val) { // all characters that json encode without escaping $chrs = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 !#$%&\'()*+,-.:;<=>?@[]^_`{|}~'; $base = strlen($chrs); $str = ''; while ($val > 0) { $str = $chrs[$val % $base] . $str; $val = (int)($val / $base); } return $str; } function gdr_decode($str) { // all characters that json encode without escaping $chrs = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 !#$%&\'()*+,-.:;<=>?@[]^_`{|}~'; $base = strlen($chrs); $map = array(); for ($i=0; $i<$base; $i++) { $map[$chrs[$i]] = $i; } $val = 0; for ($i=0; $i<strlen($str); $i++) { $val *= $base; $val += (int)$map[$str[$i]]; } return $val; } function duration($val) { if ($val < 24) { return sprintf('%d', $val).'h'; } if ($val < 24*10) { return sprintf('%1.1f', $val/24).'d'; } if ($val < 168*10) { return sprintf('%1.1f', $val/168).'w'; } //if ($val < 730*10) { // return sprintf('%1.1f', $val/730).'m'; //} return sprintf('%1.1f', $val/8760).'y'; } function cmp($val) { return strlen(gdr_encode($val))+2-strlen($val); } function insert(&$vals, $n) { $min = intval('1'.str_repeat('0', $n-1)); $max = intval(str_repeat('9', $n)); $vals[] = $min; $vals[] = $max; $cmp_min = cmp($min); $cmp_max = cmp($max); if ($cmp_min === $cmp_max) { return; } // binary search for edges if ($cmp_min+1 !== $cmp_max) { echo "ERROR: invalid search assumption: possibly missing edges: [$min => $cmp_min, $max => $cmp_max]\n"; } while ($min <= $max) { $mid = (int)(($min+$max)/2); $cmp_mid = cmp($mid); echo "trace: [$min => $cmp_min, $mid => $cmp_mid, $max=>$cmp_max]\n"; if ($cmp_min === $cmp_mid && $cmp_mid !== cmp($mid+1)) { $vals[] = $mid; $vals[] = $mid+1; return; } if ($min === $max) { return; } if ($cmp_min < $cmp_mid) { $max = $mid-1; } else { $min = $mid+1; } } } $vals = array(0); for ($i=1; $i<8; $i++) { insert($vals, $i); } $vals = array_unique($vals); sort($vals); echo sprintf("%7s %7s %7s %4s\n", 'num', 'str', 'time', 'cmp'); foreach ($vals as $val) { $enc = gdr_encode($val); $dec = gdr_decode($enc); if ($dec !== $val) { echo "ERROR: $val => $enc => $dec\n"; } else { echo sprintf("%7d %7s %7s %4d\n", $dec, "\"$enc\"", duration($val), cmp($val)); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 3
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 64
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 64
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 46
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 64
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 64
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 3
Branch analysis from position: 10
Branch analysis from position: 3
filename:       /in/cIRVV
function name:  (null)
number of ops:  66
compiled vars:  !0 = $vals, !1 = $i, !2 = $val, !3 = $enc, !4 = $dec
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   85     0  E >   ASSIGN                                                   !0, <array>
   86     1        ASSIGN                                                   !1, 1
          2      > JMP                                                      ->8
   87     3    >   INIT_FCALL                                               'insert'
          4        SEND_REF                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0          
   86     7        PRE_INC                                                  !1
          8    >   IS_SMALLER                                               !1, 8
          9      > JMPNZ                                                    ~9, ->3
   89    10    >   INIT_FCALL                                               'array_unique'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $10     
         13        ASSIGN                                                   !0, $10
   90    14        INIT_FCALL                                               'sort'
         15        SEND_REF                                                 !0
         16        DO_ICALL                                                 
   92    17        INIT_FCALL                                               'sprintf'
         18        SEND_VAL                                                 '%257s+%257s+%257s+%254s%0A'
         19        SEND_VAL                                                 'num'
         20        SEND_VAL                                                 'str'
         21        SEND_VAL                                                 'time'
         22        SEND_VAL                                                 'cmp'
         23        DO_ICALL                                         $13     
         24        ECHO                                                     $13
   93    25      > FE_RESET_R                                       $14     !0, ->64
         26    > > FE_FETCH_R                                               $14, !2, ->64
   94    27    >   INIT_FCALL                                               'gdr_encode'
         28        SEND_VAR                                                 !2
         29        DO_FCALL                                      0  $15     
         30        ASSIGN                                                   !3, $15
   95    31        INIT_FCALL                                               'gdr_decode'
         32        SEND_VAR                                                 !3
         33        DO_FCALL                                      0  $17     
         34        ASSIGN                                                   !4, $17
   96    35        IS_NOT_IDENTICAL                                         !4, !2
         36      > JMPZ                                                     ~19, ->46
   97    37    >   ROPE_INIT                                     7  ~21     'ERROR%3A+'
         38        ROPE_ADD                                      1  ~21     ~21, !2
         39        ROPE_ADD                                      2  ~21     ~21, '+%3D%3E+'
         40        ROPE_ADD                                      3  ~21     ~21, !3
         41        ROPE_ADD                                      4  ~21     ~21, '+%3D%3E+'
         42        ROPE_ADD                                      5  ~21     ~21, !4
         43        ROPE_END                                      6  ~20     ~21, '%0A'
         44        ECHO                                                     ~20
         45      > JMP                                                      ->63
   99    46    >   INIT_FCALL                                               'sprintf'
         47        SEND_VAL                                                 '%257d+%257s+%257s+%254d%0A'
         48        SEND_VAR                                                 !4
         49        ROPE_INIT                                     3  ~26     '%22'
         50        ROPE_ADD                                      1  ~26     ~26, !3
         51        ROPE_END                                      2  ~25     ~26, '%22'
         52        SEND_VAL                                                 ~25
         53        INIT_FCALL                                               'duration'
         54        SEND_VAR                                                 !2
         55        DO_FCALL                                      0  $28     
         56        SEND_VAR                                                 $28
         57        INIT_FCALL                                               'cmp'
         58        SEND_VAR                                                 !2
         59        DO_FCALL                                      0  $29     
         60        SEND_VAR                                                 $29
         61        DO_ICALL                                         $30     
         62        ECHO                                                     $30
   93    63    > > JMP                                                      ->26
         64    >   FE_FREE                                                  $14
  101    65      > RETURN                                                   1

Function gdr_encode:
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 = 6
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 6
Branch analysis from position: 15
Branch analysis from position: 6
filename:       /in/cIRVV
function name:  gdr_encode
number of ops:  17
compiled vars:  !0 = $val, !1 = $chrs, !2 = $base, !3 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+%21%23%24%25%26%27%28%29%2A%2B%2C-.%3A%3B%3C%3D%3E%3F%40%5B%5D%5E_%60%7B%7C%7D%7E'
    6     2        STRLEN                                           ~5      !1
          3        ASSIGN                                                   !2, ~5
    7     4        ASSIGN                                                   !3, ''
    8     5      > JMP                                                      ->13
    9     6    >   MOD                                              ~8      !0, !2
          7        FETCH_DIM_R                                      ~9      !1, ~8
          8        CONCAT                                           ~10     ~9, !3
          9        ASSIGN                                                   !3, ~10
   10    10        DIV                                              ~12     !0, !2
         11        CAST                                          4  ~13     ~12
         12        ASSIGN                                                   !0, ~13
    8    13    >   IS_SMALLER                                               0, !0
         14      > JMPNZ                                                    ~15, ->6
   12    15    > > RETURN                                                   !3
   13    16*     > RETURN                                                   null

End of function gdr_encode

Function gdr_decode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 7
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 16
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 16
Branch analysis from position: 25
Branch analysis from position: 16
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 7
Branch analysis from position: 13
Branch analysis from position: 7
filename:       /in/cIRVV
function name:  gdr_decode
number of ops:  27
compiled vars:  !0 = $str, !1 = $chrs, !2 = $base, !3 = $map, !4 = $i, !5 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   17     1        ASSIGN                                                   !1, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+%21%23%24%25%26%27%28%29%2A%2B%2C-.%3A%3B%3C%3D%3E%3F%40%5B%5D%5E_%60%7B%7C%7D%7E'
   18     2        STRLEN                                           ~7      !1
          3        ASSIGN                                                   !2, ~7
   19     4        ASSIGN                                                   !3, <array>
   20     5        ASSIGN                                                   !4, 0
          6      > JMP                                                      ->11
   21     7    >   FETCH_DIM_R                                      ~11     !1, !4
          8        ASSIGN_DIM                                               !3, ~11
          9        OP_DATA                                                  !4
   20    10        PRE_INC                                                  !4
         11    >   IS_SMALLER                                               !4, !2
         12      > JMPNZ                                                    ~14, ->7
   23    13    >   ASSIGN                                                   !5, 0
   24    14        ASSIGN                                                   !4, 0
         15      > JMP                                                      ->22
   25    16    >   ASSIGN_OP                                     3          !5, !2
   26    17        FETCH_DIM_R                                      ~18     !0, !4
         18        FETCH_DIM_R                                      ~19     !3, ~18
         19        CAST                                          4  ~20     ~19
         20        ASSIGN_OP                                     1          !5, ~20
   24    21        PRE_INC                                                  !4
         22    >   STRLEN                                           ~23     !0
         23        IS_SMALLER                                               !4, ~23
         24      > JMPNZ                                                    ~24, ->16
   28    25    > > RETURN                                                   !5
   29    26*     > RETURN                                                   null

End of function gdr_decode

Function duration:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 18
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 27
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cIRVV
function name:  duration
number of ops:  35
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   32     1        IS_SMALLER                                               !0, 24
          2      > JMPZ                                                     ~1, ->9
   33     3    >   INIT_FCALL                                               'sprintf'
          4        SEND_VAL                                                 '%25d'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $2      
          7        CONCAT                                           ~3      $2, 'h'
          8      > RETURN                                                   ~3
   35     9    >   IS_SMALLER                                               !0, 240
         10      > JMPZ                                                     ~4, ->18
   36    11    >   INIT_FCALL                                               'sprintf'
         12        SEND_VAL                                                 '%251.1f'
         13        DIV                                              ~5      !0, 24
         14        SEND_VAL                                                 ~5
         15        DO_ICALL                                         $6      
         16        CONCAT                                           ~7      $6, 'd'
         17      > RETURN                                                   ~7
   38    18    >   IS_SMALLER                                               !0, 1680
         19      > JMPZ                                                     ~8, ->27
   39    20    >   INIT_FCALL                                               'sprintf'
         21        SEND_VAL                                                 '%251.1f'
         22        DIV                                              ~9      !0, 168
         23        SEND_VAL                                                 ~9
         24        DO_ICALL                                         $10     
         25        CONCAT                                           ~11     $10, 'w'
         26      > RETURN                                                   ~11
   44    27    >   INIT_FCALL                                               'sprintf'
         28        SEND_VAL                                                 '%251.1f'
         29        DIV                                              ~12     !0, 8760
         30        SEND_VAL                                                 ~12
         31        DO_ICALL                                         $13     
         32        CONCAT                                           ~14     $13, 'y'
         33      > RETURN                                                   ~14
   45    34*     > RETURN                                                   null

End of function duration

Function cmp:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cIRVV
function name:  cmp
number of ops:  10
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   48     1        INIT_FCALL                                               'gdr_encode'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $1      
          4        STRLEN                                           ~2      $1
          5        ADD                                              ~3      ~2, 2
          6        STRLEN                                           ~4      !0
          7        SUB                                              ~5      ~3, ~4
          8      > RETURN                                                   ~5
   49     9*     > RETURN                                                   null

End of function cmp

Function insert:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 31
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 44
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 92
Branch analysis from position: 92
2 jumps found. (Code = 44) Position 1 = 94, Position 2 = 45
Branch analysis from position: 94
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
2 jumps found. (Code = 46) Position 1 = 69, Position 2 = 75
Branch analysis from position: 69
2 jumps found. (Code = 43) Position 1 = 76, Position 2 = 82
Branch analysis from position: 76
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 82
2 jumps found. (Code = 43) Position 1 = 84, Position 2 = 85
Branch analysis from position: 84
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 85
2 jumps found. (Code = 43) Position 1 = 87, Position 2 = 90
Branch analysis from position: 87
1 jumps found. (Code = 42) Position 1 = 92
Branch analysis from position: 92
Branch analysis from position: 90
2 jumps found. (Code = 44) Position 1 = 94, Position 2 = 45
Branch analysis from position: 94
Branch analysis from position: 45
Branch analysis from position: 75
Branch analysis from position: 44
filename:       /in/cIRVV
function name:  insert
number of ops:  95
compiled vars:  !0 = $vals, !1 = $n, !2 = $min, !3 = $max, !4 = $cmp_min, !5 = $cmp_max, !6 = $mid, !7 = $cmp_mid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   52     2        INIT_FCALL                                               'str_repeat'
          3        SEND_VAL                                                 '0'
          4        SUB                                              ~8      !1, 1
          5        SEND_VAL                                                 ~8
          6        DO_ICALL                                         $9      
          7        CONCAT                                           ~10     '1', $9
          8        CAST                                          4  ~11     ~10
          9        ASSIGN                                                   !2, ~11
   53    10        INIT_FCALL                                               'str_repeat'
         11        SEND_VAL                                                 '9'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $13     
         14        CAST                                          4  ~14     $13
         15        ASSIGN                                                   !3, ~14
   54    16        ASSIGN_DIM                                               !0
         17        OP_DATA                                                  !2
   55    18        ASSIGN_DIM                                               !0
         19        OP_DATA                                                  !3
   56    20        INIT_FCALL                                               'cmp'
         21        SEND_VAR                                                 !2
         22        DO_FCALL                                      0  $18     
         23        ASSIGN                                                   !4, $18
   57    24        INIT_FCALL                                               'cmp'
         25        SEND_VAR                                                 !3
         26        DO_FCALL                                      0  $20     
         27        ASSIGN                                                   !5, $20
   58    28        IS_IDENTICAL                                             !4, !5
         29      > JMPZ                                                     ~22, ->31
   59    30    > > RETURN                                                   null
   62    31    >   ADD                                              ~23     !4, 1
         32        IS_NOT_IDENTICAL                                         !5, ~23
         33      > JMPZ                                                     ~24, ->44
   63    34    >   ROPE_INIT                                     9  ~26     'ERROR%3A+invalid+search+assumption%3A+possibly+missing+edges%3A+%5B'
         35        ROPE_ADD                                      1  ~26     ~26, !2
         36        ROPE_ADD                                      2  ~26     ~26, '+%3D%3E+'
         37        ROPE_ADD                                      3  ~26     ~26, !4
         38        ROPE_ADD                                      4  ~26     ~26, '%2C+'
         39        ROPE_ADD                                      5  ~26     ~26, !3
         40        ROPE_ADD                                      6  ~26     ~26, '+%3D%3E+'
         41        ROPE_ADD                                      7  ~26     ~26, !5
         42        ROPE_END                                      8  ~25     ~26, '%5D%0A'
         43        ECHO                                                     ~25
   65    44    > > JMP                                                      ->92
   66    45    >   ADD                                              ~31     !2, !3
         46        DIV                                              ~32     ~31, 2
         47        CAST                                          4  ~33     ~32
         48        ASSIGN                                                   !6, ~33
   67    49        INIT_FCALL                                               'cmp'
         50        SEND_VAR                                                 !6
         51        DO_FCALL                                      0  $35     
         52        ASSIGN                                                   !7, $35
   68    53        ROPE_INIT                                    13  ~38     'trace%3A+%5B'
         54        ROPE_ADD                                      1  ~38     ~38, !2
         55        ROPE_ADD                                      2  ~38     ~38, '+%3D%3E+'
         56        ROPE_ADD                                      3  ~38     ~38, !4
         57        ROPE_ADD                                      4  ~38     ~38, '%2C+'
         58        ROPE_ADD                                      5  ~38     ~38, !6
         59        ROPE_ADD                                      6  ~38     ~38, '+%3D%3E+'
         60        ROPE_ADD                                      7  ~38     ~38, !7
         61        ROPE_ADD                                      8  ~38     ~38, '%2C+'
         62        ROPE_ADD                                      9  ~38     ~38, !3
         63        ROPE_ADD                                     10  ~38     ~38, '%3D%3E'
         64        ROPE_ADD                                     11  ~38     ~38, !5
         65        ROPE_END                                     12  ~37     ~38, '%5D%0A'
         66        ECHO                                                     ~37
   69    67        IS_IDENTICAL                                     ~45     !4, !7
         68      > JMPZ_EX                                          ~45     ~45, ->75
         69    >   INIT_FCALL                                               'cmp'
         70        ADD                                              ~46     !6, 1
         71        SEND_VAL                                                 ~46
         72        DO_FCALL                                      0  $47     
         73        IS_NOT_IDENTICAL                                 ~48     !7, $47
         74        BOOL                                             ~45     ~48
         75    > > JMPZ                                                     ~45, ->82
   70    76    >   ASSIGN_DIM                                               !0
         77        OP_DATA                                                  !6
   71    78        ADD                                              ~51     !6, 1
         79        ASSIGN_DIM                                               !0
         80        OP_DATA                                                  ~51
   72    81      > RETURN                                                   null
   74    82    >   IS_IDENTICAL                                             !2, !3
         83      > JMPZ                                                     ~52, ->85
   75    84    > > RETURN                                                   null
   77    85    >   IS_SMALLER                                               !4, !7
         86      > JMPZ                                                     ~53, ->90
   78    87    >   SUB                                              ~54     !6, 1
         88        ASSIGN                                                   !3, ~54
         89      > JMP                                                      ->92
   80    90    >   ADD                                              ~56     !6, 1
         91        ASSIGN                                                   !2, ~56
   65    92    >   IS_SMALLER_OR_EQUAL                                      !2, !3
         93      > JMPNZ                                                    ~58, ->45
   83    94    > > RETURN                                                   null

End of function insert

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
210.19 ms | 967 KiB | 32 Q