3v4l.org

run code in 300+ PHP versions simultaneously
<?php class LookAndSay { private static function tokenize($input) { $currentDigit = substr($input, 0, 1); $n = 0; $result = []; foreach(str_split($input) as $digit) { if($currentDigit !== $digit) { $result[] = [$currentDigit, $n]; $n = 0; $currentDigit = $digit; } $n++; } $result[] = [$currentDigit, $n]; return $result; } public static function transform($input) { $tokens = self::tokenize($input); $result = ''; foreach($tokens as $token) { list($digit, $n) = $token; $result .= $n . $digit; } return $result; } } $input = '3113322113'; for($i = 0; $i < 40; $i++) {gc_collect_cycles(); $input = LookAndSay::transform($input);} print strlen($input);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 3
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 3
Branch analysis from position: 12
Branch analysis from position: 3
filename:       /in/NPnJ8
function name:  (null)
number of ops:  15
compiled vars:  !0 = $input, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   ASSIGN                                                   !0, '3113322113'
   34     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->10
          3    >   INIT_FCALL                                               'gc_collect_cycles'
          4        DO_ICALL                                                 
          5        INIT_STATIC_METHOD_CALL                                  'LookAndSay', 'transform'
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0  $5      
          8        ASSIGN                                                   !0, $5
          9        PRE_INC                                                  !1
         10    >   IS_SMALLER                                               !1, 40
         11      > JMPNZ                                                    ~8, ->3
         12    >   STRLEN                                           ~9      !0
         13        ECHO                                                     ~9
         14      > RETURN                                                   1

Class LookAndSay:
Function tokenize:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 24
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 24
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 22
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 22
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/NPnJ8
function name:  tokenize
number of ops:  31
compiled vars:  !0 = $input, !1 = $currentDigit, !2 = $n, !3 = $result, !4 = $digit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    6     1        INIT_FCALL                                               'substr'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 0
          4        SEND_VAL                                                 1
          5        DO_ICALL                                         $5      
          6        ASSIGN                                                   !1, $5
    7     7        ASSIGN                                                   !2, 0
    8     8        ASSIGN                                                   !3, <array>
    9     9        INIT_FCALL                                               'str_split'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $9      
         12      > FE_RESET_R                                       $10     $9, ->24
         13    > > FE_FETCH_R                                               $10, !4, ->24
   10    14    >   IS_NOT_IDENTICAL                                         !1, !4
         15      > JMPZ                                                     ~11, ->22
   11    16    >   INIT_ARRAY                                       ~13     !1
         17        ADD_ARRAY_ELEMENT                                ~13     !2
         18        ASSIGN_DIM                                               !3
         19        OP_DATA                                                  ~13
   12    20        ASSIGN                                                   !2, 0
   13    21        ASSIGN                                                   !1, !4
   15    22    >   PRE_INC                                                  !2
    9    23      > JMP                                                      ->13
         24    >   FE_FREE                                                  $10
   17    25        INIT_ARRAY                                       ~18     !1
         26        ADD_ARRAY_ELEMENT                                ~18     !2
         27        ASSIGN_DIM                                               !3
         28        OP_DATA                                                  ~18
   18    29      > RETURN                                                   !3
   19    30*     > RETURN                                                   null

End of function tokenize

Function transform:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 17
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/NPnJ8
function name:  transform
number of ops:  20
compiled vars:  !0 = $input, !1 = $tokens, !2 = $result, !3 = $token, !4 = $digit, !5 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   23     1        INIT_STATIC_METHOD_CALL                                  'tokenize'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $6      
          4        ASSIGN                                                   !1, $6
   24     5        ASSIGN                                                   !2, ''
   25     6      > FE_RESET_R                                       $9      !1, ->17
          7    > > FE_FETCH_R                                               $9, !3, ->17
   26     8    >   QM_ASSIGN                                        ~10     !3
          9        FETCH_LIST_R                                     $11     ~10, 0
         10        ASSIGN                                                   !4, $11
         11        FETCH_LIST_R                                     $13     ~10, 1
         12        ASSIGN                                                   !5, $13
         13        FREE                                                     ~10
   27    14        CONCAT                                           ~15     !5, !4
         15        ASSIGN_OP                                     8          !2, ~15
   25    16      > JMP                                                      ->7
         17    >   FE_FREE                                                  $9
   29    18      > RETURN                                                   !2
   30    19*     > RETURN                                                   null

End of function transform

End of class LookAndSay.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.06 ms | 1400 KiB | 19 Q