3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Returns the total number of $count-length strings generatable from $letters. function getPermCount($letters, $count) { $result = 1; // k characters from a set of n has n!/(n-k)! possible combinations for($i = strlen($letters) - $count + 1; $i <= strlen($letters); $i++) { $result *= $i; } return $result; } // Decodes $index to a $count-length string from $letters, no repeat chars. function getPerm($letters, $count, $index) { $result = array(); for($i = 0; $i < $count; $i++) { $pos = $index % strlen($letters); $result[] = $letters[$pos]; $index = ($index-$pos)/strlen($letters); $letters = substr($letters, 0, $pos) . substr($letters, $pos+1); } sort($result); //array_unique($r, SORT_REGULAR); return implode("", $result); } $r = array(); //$letters = 'abcdefghijklm'; $letters = 'abc'; $len = strlen($letters); for ($c = 1; $c <= $len; $c++) for($i = 0; $i < getPermCount($letters, $c); $i++) $r[] = getPerm($letters, $c, $i); //print_r(array_unique($r, SORT_REGULAR)); $r = array_unique($r, SORT_REGULAR); print_r(count($r));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 6
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 8
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 6
Branch analysis from position: 25
Branch analysis from position: 6
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 8
Branch analysis from position: 22
Branch analysis from position: 8
filename:       /in/LH9ri
function name:  (null)
number of ops:  35
compiled vars:  !0 = $r, !1 = $letters, !2 = $len, !3 = $c, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   ASSIGN                                                   !0, <array>
   31     1        ASSIGN                                                   !1, 'abc'
   32     2        STRLEN                                           ~7      !1
          3        ASSIGN                                                   !2, ~7
   34     4        ASSIGN                                                   !3, 1
          5      > JMP                                                      ->23
   35     6    >   ASSIGN                                                   !4, 0
          7      > JMP                                                      ->16
   36     8    >   INIT_FCALL                                               'getperm'
          9        SEND_VAR                                                 !1
         10        SEND_VAR                                                 !3
         11        SEND_VAR                                                 !4
         12        DO_FCALL                                      0  $12     
         13        ASSIGN_DIM                                               !0
         14        OP_DATA                                                  $12
   35    15        PRE_INC                                                  !4
         16    >   INIT_FCALL                                               'getpermcount'
         17        SEND_VAR                                                 !1
         18        SEND_VAR                                                 !3
         19        DO_FCALL                                      0  $14     
         20        IS_SMALLER                                               !4, $14
         21      > JMPNZ                                                    ~15, ->8
   34    22    >   PRE_INC                                                  !3
         23    >   IS_SMALLER_OR_EQUAL                                      !3, !2
         24      > JMPNZ                                                    ~17, ->6
   39    25    >   INIT_FCALL                                               'array_unique'
         26        SEND_VAR                                                 !0
         27        SEND_VAL                                                 0
         28        DO_ICALL                                         $18     
         29        ASSIGN                                                   !0, $18
   40    30        INIT_FCALL                                               'print_r'
         31        COUNT                                            ~20     !0
         32        SEND_VAL                                                 ~20
         33        DO_ICALL                                                 
         34      > RETURN                                                   1

Function getpermcount:
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 = 13, Position 2 = 8
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 8
Branch analysis from position: 13
Branch analysis from position: 8
filename:       /in/LH9ri
function name:  getPermCount
number of ops:  15
compiled vars:  !0 = $letters, !1 = $count, !2 = $result, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        ASSIGN                                                   !2, 1
    7     3        STRLEN                                           ~5      !0
          4        SUB                                              ~6      ~5, !1
          5        ADD                                              ~7      ~6, 1
          6        ASSIGN                                                   !3, ~7
          7      > JMP                                                      ->10
    8     8    >   ASSIGN_OP                                     3          !2, !3
    7     9        PRE_INC                                                  !3
         10    >   STRLEN                                           ~11     !0
         11        IS_SMALLER_OR_EQUAL                                      !3, ~11
         12      > JMPNZ                                                    ~12, ->8
   10    13    > > RETURN                                                   !2
   11    14*     > RETURN                                                   null

End of function getpermcount

Function getperm:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 6
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 6
Branch analysis from position: 31
Branch analysis from position: 6
filename:       /in/LH9ri
function name:  getPerm
number of ops:  40
compiled vars:  !0 = $letters, !1 = $count, !2 = $index, !3 = $result, !4 = $i, !5 = $pos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   16     3        ASSIGN                                                   !3, <array>
   17     4        ASSIGN                                                   !4, 0
          5      > JMP                                                      ->29
   19     6    >   STRLEN                                           ~8      !0
          7        MOD                                              ~9      !2, ~8
          8        ASSIGN                                                   !5, ~9
   20     9        FETCH_DIM_R                                      ~12     !0, !5
         10        ASSIGN_DIM                                               !3
         11        OP_DATA                                                  ~12
   21    12        SUB                                              ~13     !2, !5
         13        STRLEN                                           ~14     !0
         14        DIV                                              ~15     ~13, ~14
         15        ASSIGN                                                   !2, ~15
   22    16        INIT_FCALL                                               'substr'
         17        SEND_VAR                                                 !0
         18        SEND_VAL                                                 0
         19        SEND_VAR                                                 !5
         20        DO_ICALL                                         $17     
         21        INIT_FCALL                                               'substr'
         22        SEND_VAR                                                 !0
         23        ADD                                              ~18     !5, 1
         24        SEND_VAL                                                 ~18
         25        DO_ICALL                                         $19     
         26        CONCAT                                           ~20     $17, $19
         27        ASSIGN                                                   !0, ~20
   17    28        PRE_INC                                                  !4
         29    >   IS_SMALLER                                               !4, !1
         30      > JMPNZ                                                    ~23, ->6
   24    31    >   INIT_FCALL                                               'sort'
         32        SEND_REF                                                 !3
         33        DO_ICALL                                                 
   26    34        INIT_FCALL                                               'implode'
         35        SEND_VAL                                                 ''
         36        SEND_VAR                                                 !3
         37        DO_ICALL                                         $25     
         38      > RETURN                                                   $25
   27    39*     > RETURN                                                   null

End of function getperm

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.4 ms | 1398 KiB | 25 Q