3v4l.org

run code in 300+ PHP versions simultaneously
<?php $facts = []; function fact($N, &$facts) { if ($N<=1) { return 1; } if (!array_key_exists($N, $facts)) { $facts[$N] = $N * fact($N - 1, $facts); } return $facts[$N]; } function C($n, $k, &$facts) { return fact($n, $facts) / fact($k, $facts) / fact($n - $k, $facts); } function combination ($index, $k, $A, $facts) { $res = [0]; $n = sizeof($A); $s = 0; for ($t = 1; $t <= $k; $t++) { $j = $res[$t - 1] + 1; while (($j < ($n - $k + $t)) && (($s + C($n - $j, $k - $t, $facts)) <= $index)) { $s += C($n - $j, $k - $t, $facts); $j++; } $res[] = $j; } array_splice($res, 0, 1); print_r($res); } $m = [1,2,3,4,5]; for ($i = 0; $i < C(sizeof($m), 3, $facts); $i++) { combination($i, 3, array_slice($m, 0), $facts); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 4
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 4
Branch analysis from position: 23
Branch analysis from position: 4
filename:       /in/47oFq
function name:  (null)
number of ops:  24
compiled vars:  !0 = $facts, !1 = $m, !2 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   37     1        ASSIGN                                                   !1, <array>
   39     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->15
   40     4    >   INIT_FCALL                                               'combination'
          5        SEND_VAR                                                 !2
          6        SEND_VAL                                                 3
          7        INIT_FCALL                                               'array_slice'
          8        SEND_VAR                                                 !1
          9        SEND_VAL                                                 0
         10        DO_ICALL                                         $6      
         11        SEND_VAR                                                 $6
         12        SEND_VAR                                                 !0
         13        DO_FCALL                                      0          
   39    14        PRE_INC                                                  !2
         15    >   INIT_FCALL                                               'c'
         16        COUNT                                            ~9      !1
         17        SEND_VAL                                                 ~9
         18        SEND_VAL                                                 3
         19        SEND_REF                                                 !0
         20        DO_FCALL                                      0  $10     
         21        IS_SMALLER                                               !2, $10
         22      > JMPNZ                                                    ~11, ->4
   41    23    > > RETURN                                                   1

Function fact:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 16
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/47oFq
function name:  fact
number of ops:  19
compiled vars:  !0 = $N, !1 = $facts
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        IS_SMALLER_OR_EQUAL                                      !0, 1
          3      > JMPZ                                                     ~2, ->5
    7     4    > > RETURN                                                   1
    9     5    >   ARRAY_KEY_EXISTS                                 ~3      !0, !1
          6        BOOL_NOT                                         ~4      ~3
          7      > JMPZ                                                     ~4, ->16
   10     8    >   INIT_FCALL_BY_NAME                                       'fact'
          9        SUB                                              ~6      !0, 1
         10        SEND_VAL_EX                                              ~6
         11        SEND_VAR_EX                                              !1
         12        DO_FCALL                                      0  $7      
         13        MUL                                              ~8      !0, $7
         14        ASSIGN_DIM                                               !1, !0
         15        OP_DATA                                                  ~8
   12    16    >   FETCH_DIM_R                                      ~9      !1, !0
         17      > RETURN                                                   ~9
   13    18*     > RETURN                                                   null

End of function fact

Function c:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/47oFq
function name:  C
number of ops:  20
compiled vars:  !0 = $n, !1 = $k, !2 = $facts
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   17     3        INIT_FCALL                                               'fact'
          4        SEND_VAR                                                 !0
          5        SEND_REF                                                 !2
          6        DO_FCALL                                      0  $3      
          7        INIT_FCALL                                               'fact'
          8        SEND_VAR                                                 !1
          9        SEND_REF                                                 !2
         10        DO_FCALL                                      0  $4      
         11        DIV                                              ~5      $3, $4
         12        INIT_FCALL                                               'fact'
         13        SUB                                              ~6      !0, !1
         14        SEND_VAL                                                 ~6
         15        SEND_REF                                                 !2
         16        DO_FCALL                                      0  $7      
         17        DIV                                              ~8      ~5, $7
         18      > RETURN                                                   ~8
   18    19*     > RETURN                                                   null

End of function c

Function combination:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 10
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 46) Position 1 = 28, Position 2 = 38
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 15
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 10
Branch analysis from position: 44
Branch analysis from position: 10
Branch analysis from position: 15
2 jumps found. (Code = 46) Position 1 = 28, Position 2 = 38
Branch analysis from position: 28
Branch analysis from position: 38
Branch analysis from position: 38
filename:       /in/47oFq
function name:  combination
number of ops:  53
compiled vars:  !0 = $index, !1 = $k, !2 = $A, !3 = $facts, !4 = $res, !5 = $n, !6 = $s, !7 = $t, !8 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   22     4        ASSIGN                                                   !4, <array>
   23     5        COUNT                                            ~10     !2
          6        ASSIGN                                                   !5, ~10
   24     7        ASSIGN                                                   !6, 0
   25     8        ASSIGN                                                   !7, 1
          9      > JMP                                                      ->42
   26    10    >   SUB                                              ~14     !7, 1
         11        FETCH_DIM_R                                      ~15     !4, ~14
         12        ADD                                              ~16     ~15, 1
         13        ASSIGN                                                   !8, ~16
   27    14      > JMP                                                      ->24
   28    15    >   INIT_FCALL                                               'c'
         16        SUB                                              ~18     !5, !8
         17        SEND_VAL                                                 ~18
         18        SUB                                              ~19     !1, !7
         19        SEND_VAL                                                 ~19
         20        SEND_REF                                                 !3
         21        DO_FCALL                                      0  $20     
         22        ASSIGN_OP                                     1          !6, $20
   29    23        PRE_INC                                                  !8
   27    24    >   SUB                                              ~23     !5, !1
         25        ADD                                              ~24     ~23, !7
         26        IS_SMALLER                                       ~25     !8, ~24
         27      > JMPZ_EX                                          ~25     ~25, ->38
         28    >   INIT_FCALL                                               'c'
         29        SUB                                              ~26     !5, !8
         30        SEND_VAL                                                 ~26
         31        SUB                                              ~27     !1, !7
         32        SEND_VAL                                                 ~27
         33        SEND_REF                                                 !3
         34        DO_FCALL                                      0  $28     
         35        ADD                                              ~29     !6, $28
         36        IS_SMALLER_OR_EQUAL                              ~30     ~29, !0
         37        BOOL                                             ~25     ~30
         38    > > JMPNZ                                                    ~25, ->15
   31    39    >   ASSIGN_DIM                                               !4
         40        OP_DATA                                                  !8
   25    41        PRE_INC                                                  !7
         42    >   IS_SMALLER_OR_EQUAL                                      !7, !1
         43      > JMPNZ                                                    ~33, ->10
   33    44    >   INIT_FCALL                                               'array_splice'
         45        SEND_REF                                                 !4
         46        SEND_VAL                                                 0
         47        SEND_VAL                                                 1
         48        DO_ICALL                                                 
   34    49        INIT_FCALL                                               'print_r'
         50        SEND_VAR                                                 !4
         51        DO_ICALL                                                 
   35    52      > RETURN                                                   null

End of function combination

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.9 ms | 1415 KiB | 26 Q