3v4l.org

run code in 300+ PHP versions simultaneously
<?php function combinations(int $n, int $k):array { function combine(int $n, int $k, int $start = 0, array &$result = [], array &$all = []) { if ($k == 0) { $all[] = $result; return; } for ($i = $start; $i <= $n - $k; $i++) { $result[$k] = $i; combine($n, $k - 1, $i + 1, $result, $all); } } $res = []; $all = []; combine($n, $k, 0, $res, $all); return $all; } function may_add_combination_to_set(array $combination, array $sets) { foreach ($sets as $combinationInSet) { if (count(array_intersect($combinationInSet, $combination)) !== 1) { return false; } } return true; } $combinations = combinations(31, 6); $sets = []; foreach ($combinations as $combination) { if (may_add_combination_to_set($combination, $sets)) { $sets[] = $combination; } } count($sets);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 16
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 16
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 15
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/vq7d6
function name:  (null)
number of ops:  20
compiled vars:  !0 = $combinations, !1 = $sets, !2 = $combination
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   INIT_FCALL                                               'combinations'
          1        SEND_VAL                                                 31
          2        SEND_VAL                                                 6
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !0, $3
   41     5        ASSIGN                                                   !1, <array>
   43     6      > FE_RESET_R                                       $6      !0, ->16
          7    > > FE_FETCH_R                                               $6, !2, ->16
   44     8    >   INIT_FCALL                                               'may_add_combination_to_set'
          9        SEND_VAR                                                 !2
         10        SEND_VAR                                                 !1
         11        DO_FCALL                                      0  $7      
         12      > JMPZ                                                     $7, ->15
   45    13    >   ASSIGN_DIM                                               !1
         14        OP_DATA                                                  !2
   43    15    > > JMP                                                      ->7
         16    >   FE_FREE                                                  $6
   49    17        COUNT                                            ~9      !1
         18        FREE                                                     ~9
         19      > RETURN                                                   1

Function combinations:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vq7d6
function name:  combinations
number of ops:  16
compiled vars:  !0 = $n, !1 = $k, !2 = $res, !3 = $all
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        DECLARE_FUNCTION                                         'combine'
   19     3        ASSIGN                                                   !2, <array>
   20     4        ASSIGN                                                   !3, <array>
   22     5        INIT_FCALL_BY_NAME                                       'combine'
          6        SEND_VAR_EX                                              !0
          7        SEND_VAR_EX                                              !1
          8        SEND_VAL_EX                                              0
          9        SEND_VAR_EX                                              !2
         10        SEND_VAR_EX                                              !3
         11        DO_FCALL                                      0          
   24    12        VERIFY_RETURN_TYPE                                       !3
         13      > RETURN                                                   !3
   25    14*       VERIFY_RETURN_TYPE                                       
         15*     > RETURN                                                   null

End of function combinations

Function %00combine%2Fin%2Fvq7d6%3A6%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
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 = 44) Position 1 = 27, Position 2 = 12
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 12
Branch analysis from position: 27
Branch analysis from position: 12
filename:       /in/vq7d6
function name:  combine
number of ops:  28
compiled vars:  !0 = $n, !1 = $k, !2 = $start, !3 = $result, !4 = $all, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      0
          3        RECV_INIT                                        !3      <array>
          4        RECV_INIT                                        !4      <array>
    8     5        IS_EQUAL                                                 !1, 0
          6      > JMPZ                                                     ~6, ->10
    9     7    >   ASSIGN_DIM                                               !4
          8        OP_DATA                                                  !3
   10     9      > RETURN                                                   null
   13    10    >   ASSIGN                                                   !5, !2
         11      > JMP                                                      ->24
   14    12    >   ASSIGN_DIM                                               !3, !1
         13        OP_DATA                                                  !5
   15    14        INIT_FCALL_BY_NAME                                       'combine'
         15        SEND_VAR_EX                                              !0
         16        SUB                                              ~10     !1, 1
         17        SEND_VAL_EX                                              ~10
         18        ADD                                              ~11     !5, 1
         19        SEND_VAL_EX                                              ~11
         20        SEND_VAR_EX                                              !3
         21        SEND_VAR_EX                                              !4
         22        DO_FCALL                                      0          
   13    23        PRE_INC                                                  !5
         24    >   SUB                                              ~14     !0, !1
         25        IS_SMALLER_OR_EQUAL                                      !5, ~14
         26      > JMPNZ                                                    ~15, ->12
   17    27    > > RETURN                                                   null

End of function %00combine%2Fin%2Fvq7d6%3A6%240

Function may_add_combination_to_set:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 14
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 14
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/vq7d6
function name:  may_add_combination_to_set
number of ops:  17
compiled vars:  !0 = $combination, !1 = $sets, !2 = $combinationInSet
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   29     2      > FE_RESET_R                                       $3      !1, ->14
          3    > > FE_FETCH_R                                               $3, !2, ->14
   30     4    >   INIT_FCALL                                               'array_intersect'
          5        SEND_VAR                                                 !2
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $4      
          8        COUNT                                            ~5      $4
          9        IS_NOT_IDENTICAL                                         ~5, 1
         10      > JMPZ                                                     ~6, ->13
   31    11    >   FE_FREE                                                  $3
         12      > RETURN                                                   <false>
   29    13    > > JMP                                                      ->3
         14    >   FE_FREE                                                  $3
   35    15      > RETURN                                                   <true>
   36    16*     > RETURN                                                   null

End of function may_add_combination_to_set

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.61 ms | 1407 KiB | 17 Q