3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Run it: php r30.php * Run it with a custom number of rows: php r30.php <number> * Have fun :) */ function createRows($numRows, $rule) { $getNextRow = function ($currRow) use ($rule) { $nextRow = [0, 0]; for ($i = 1, $iMax = count($currRow) - 1; $i < $iMax; $i++) { $nextRow[] = $rule[$currRow[$i - 1] . $currRow[$i] . $currRow[$i + 1]]; } array_push($nextRow, 0, 0); return $nextRow; }; $rows[0] = [0, 0, 1, 0, 0]; for ($i = 1; $i <= $numRows; $i++) { $rows[$i] = $getNextRow($rows[$i - 1]); } return $rows; } function displayRows($rows, $isDownwards, $micSleep) { $rowCount = count($rows); $getRow = function ($rows, $isDownwards) use ($rowCount) { if ($isDownwards === true) { for ($i = 0; $i < $rowCount; $i++) { yield [$i, $rows[$i]]; } } else { for ($i = $rowCount - 1; $i >= 0; $i--) { yield [$i, $rows[$i]]; } } }; foreach ($getRow($rows, $isDownwards) as [$pad, $row]) { echo str_repeat(' ', $rowCount - $pad); foreach ($row as $cell) { echo $cell === 1 ? '█' : ' '; } echo PHP_EOL; usleep($micSleep); } } // https://en.wikipedia.org/wiki/Rule_30 const RULE_30 = [ '111' => 0, '110' => 0, '101' => 0, '100' => 1, '011' => 1, '010' => 1, '001' => 1, '000' => 0, ]; $numRows = isset($argv[1]) && (int)$argv[1] > 0 && (int)$argv[1] <= 1000 ? (int)$argv[1] : 80; $rows = createRows($numRows, RULE_30); while (true) { displayRows($rows, true, 5000); displayRows($rows, false, 5000); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
2 jumps found. (Code = 46) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 26
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 26
Branch analysis from position: 37
Branch analysis from position: 26
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 12
Branch analysis from position: 7
filename:       /in/cEdPL
function name:  (null)
number of ops:  38
compiled vars:  !0 = $numRows, !1 = $argv, !2 = $rows
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   DECLARE_CONST                                            'RULE_30', <array>
   55     1        ISSET_ISEMPTY_DIM_OBJ                         0  ~3      !1, 1
          2      > JMPZ_EX                                          ~3      ~3, ->7
          3    >   FETCH_DIM_R                                      ~4      !1, 1
          4        CAST                                          4  ~5      ~4
          5        IS_SMALLER                                       ~6      0, ~5
          6        BOOL                                             ~3      ~6
          7    > > JMPZ_EX                                          ~3      ~3, ->12
          8    >   FETCH_DIM_R                                      ~7      !1, 1
          9        CAST                                          4  ~8      ~7
         10        IS_SMALLER_OR_EQUAL                              ~9      ~8, 1000
         11        BOOL                                             ~3      ~9
         12    > > JMPZ                                                     ~3, ->17
         13    >   FETCH_DIM_R                                      ~10     !1, 1
         14        CAST                                          4  ~11     ~10
         15        QM_ASSIGN                                        ~12     ~11
         16      > JMP                                                      ->18
         17    >   QM_ASSIGN                                        ~12     80
         18    >   ASSIGN                                                   !0, ~12
   56    19        INIT_FCALL                                               'createrows'
         20        SEND_VAR                                                 !0
         21        FETCH_CONSTANT                                   ~14     'RULE_30'
         22        SEND_VAL                                                 ~14
         23        DO_FCALL                                      0  $15     
         24        ASSIGN                                                   !2, $15
   57    25      > JMP                                                      ->36
   58    26    >   INIT_FCALL                                               'displayrows'
         27        SEND_VAR                                                 !2
         28        SEND_VAL                                                 <true>
         29        SEND_VAL                                                 5000
         30        DO_FCALL                                      0          
   59    31        INIT_FCALL                                               'displayrows'
         32        SEND_VAR                                                 !2
         33        SEND_VAL                                                 <false>
         34        SEND_VAL                                                 5000
         35        DO_FCALL                                      0          
   57    36    > > JMPNZ                                                    <true>, ->26
   60    37    > > RETURN                                                   1

Function createrows:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 9
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 9
Branch analysis from position: 20
Branch analysis from position: 9
filename:       /in/cEdPL
function name:  createRows
number of ops:  22
compiled vars:  !0 = $numRows, !1 = $rule, !2 = $getNextRow, !3 = $rows, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FcEdPL%3A8%240'
          3        BIND_LEXICAL                                             ~5, !1
          4        ASSIGN                                                   !2, ~5
   16     5        ASSIGN_DIM                                               !3, 0
          6        OP_DATA                                                  <array>
   17     7        ASSIGN                                                   !4, 1
          8      > JMP                                                      ->18
   18     9    >   INIT_DYNAMIC_CALL                                        !2
         10        CHECK_FUNC_ARG                                           
         11        SUB                                              ~10     !4, 1
         12        FETCH_DIM_FUNC_ARG                               $11     !3, ~10
         13        SEND_FUNC_ARG                                            $11
         14        DO_FCALL                                      0  $12     
         15        ASSIGN_DIM                                               !3, !4
         16        OP_DATA                                                  $12
   17    17        PRE_INC                                                  !4
         18    >   IS_SMALLER_OR_EQUAL                                      !4, !0
         19      > JMPNZ                                                    ~14, ->9
   20    20    > > RETURN                                                   !3
   21    21*     > RETURN                                                   null

End of function createrows

Function %00%7Bclosure%7D%2Fin%2FcEdPL%3A8%240:
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 = 8
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 8
Branch analysis from position: 21
Branch analysis from position: 8
filename:       /in/cEdPL
function name:  {closure}
number of ops:  28
compiled vars:  !0 = $currRow, !1 = $rule, !2 = $nextRow, !3 = $i, !4 = $iMax
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
    9     2        ASSIGN                                                   !2, <array>
   10     3        ASSIGN                                                   !3, 1
          4        COUNT                                            ~7      !0
          5        SUB                                              ~8      ~7, 1
          6        ASSIGN                                                   !4, ~8
          7      > JMP                                                      ->19
   11     8    >   SUB                                              ~11     !3, 1
          9        FETCH_DIM_R                                      ~12     !0, ~11
         10        FETCH_DIM_R                                      ~13     !0, !3
         11        CONCAT                                           ~14     ~12, ~13
         12        ADD                                              ~15     !3, 1
         13        FETCH_DIM_R                                      ~16     !0, ~15
         14        CONCAT                                           ~17     ~14, ~16
         15        FETCH_DIM_R                                      ~18     !1, ~17
         16        ASSIGN_DIM                                               !2
         17        OP_DATA                                                  ~18
   10    18        PRE_INC                                                  !3
         19    >   IS_SMALLER                                               !3, !4
         20      > JMPNZ                                                    ~20, ->8
   13    21    >   INIT_FCALL                                               'array_push'
         22        SEND_REF                                                 !2
         23        SEND_VAL                                                 0
         24        SEND_VAL                                                 0
         25        DO_ICALL                                                 
   14    26      > RETURN                                                   !2
   15    27*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FcEdPL%3A8%240

Function displayrows:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 40
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 40
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 34
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 34
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 31
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 34
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
filename:       /in/cEdPL
function name:  displayRows
number of ops:  42
compiled vars:  !0 = $rows, !1 = $isDownwards, !2 = $micSleep, !3 = $rowCount, !4 = $getRow, !5 = $pad, !6 = $row, !7 = $cell
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   23     3        COUNT                                            ~8      !0
          4        ASSIGN                                                   !3, ~8
   24     5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FcEdPL%3A24%241'
          6        BIND_LEXICAL                                             ~10, !3
          7        ASSIGN                                                   !4, ~10
   35     8        INIT_DYNAMIC_CALL                                        !4
          9        SEND_VAR_EX                                              !0
         10        SEND_VAR_EX                                              !1
         11        DO_FCALL                                      0  $12     
         12      > FE_RESET_R                                       $13     $12, ->40
         13    > > FE_FETCH_R                                               $13, $14, ->40
         14    >   FETCH_LIST_R                                     $15     $14, 0
         15        ASSIGN                                                   !5, $15
         16        FETCH_LIST_R                                     $17     $14, 1
         17        ASSIGN                                                   !6, $17
         18        FREE                                                     $14
   36    19        INIT_FCALL                                               'str_repeat'
         20        SEND_VAL                                                 '+'
         21        SUB                                              ~19     !3, !5
         22        SEND_VAL                                                 ~19
         23        DO_ICALL                                         $20     
         24        ECHO                                                     $20
   37    25      > FE_RESET_R                                       $21     !6, ->34
         26    > > FE_FETCH_R                                               $21, !7, ->34
   38    27    >   IS_IDENTICAL                                             !7, 1
         28      > JMPZ                                                     ~22, ->31
         29    >   QM_ASSIGN                                        ~23     '%E2%96%88'
         30      > JMP                                                      ->32
         31    >   QM_ASSIGN                                        ~23     '+'
         32    >   ECHO                                                     ~23
   37    33      > JMP                                                      ->26
         34    >   FE_FREE                                                  $21
   40    35        ECHO                                                     '%0A'
   41    36        INIT_FCALL                                               'usleep'
         37        SEND_VAR                                                 !2
         38        DO_ICALL                                                 
   35    39      > JMP                                                      ->13
         40    >   FE_FREE                                                  $13
   43    41      > RETURN                                                   null

End of function displayrows

Function %00%7Bclosure%7D%2Fin%2FcEdPL%3A24%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 16
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 8
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 8
Branch analysis from position: 15
Branch analysis from position: 8
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 19
Branch analysis from position: 26
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 19
Branch analysis from position: 26
Branch analysis from position: 19
filename:       /in/cEdPL
function name:  {closure}
number of ops:  27
compiled vars:  !0 = $rows, !1 = $isDownwards, !2 = $rowCount, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        GENERATOR_CREATE                                         
          3        BIND_STATIC                                              !2
   25     4        TYPE_CHECK                                    8          !1
          5      > JMPZ                                                     ~4, ->16
   26     6    >   ASSIGN                                                   !3, 0
          7      > JMP                                                      ->13
   27     8    >   INIT_ARRAY                                       ~6      !3
          9        FETCH_DIM_R                                      ~7      !0, !3
         10        ADD_ARRAY_ELEMENT                                ~6      ~7
         11        YIELD                                                    ~6
   26    12        PRE_INC                                                  !3
         13    >   IS_SMALLER                                               !3, !2
         14      > JMPNZ                                                    ~10, ->8
         15    > > JMP                                                      ->26
   30    16    >   SUB                                              ~11     !2, 1
         17        ASSIGN                                                   !3, ~11
         18      > JMP                                                      ->24
   31    19    >   INIT_ARRAY                                       ~13     !3
         20        FETCH_DIM_R                                      ~14     !0, !3
         21        ADD_ARRAY_ELEMENT                                ~13     ~14
         22        YIELD                                                    ~13
   30    23        PRE_DEC                                                  !3
         24    >   IS_SMALLER_OR_EQUAL                                      0, !3
         25      > JMPNZ                                                    ~17, ->19
   34    26    > > GENERATOR_RETURN                                         

End of function %00%7Bclosure%7D%2Fin%2FcEdPL%3A24%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.01 ms | 1415 KiB | 22 Q