3v4l.org

run code in 300+ PHP versions simultaneously
<?php function ranking ($players_scores) { $players = array_column($players_scores, 0); $scores = array_column($players_scores, 1); array_multisort($scores, SORT_DESC, $players, SORT_ASC, $players_scores); return $players_scores; } function round_system ($players_scores) { $players_count ($players_scores); return round_count_system ($players_count); } function round_count_system ($players_count) { if ($players_count < 2) return no_match ($players_count); if ($players_count <= 5) return everybody_battles_everybody ($players_count); if ($players_count == 8) return groups_with_N_players (4, (int)($players_count/4)); if ($players_count % 4 == 0 && $players_count/4<=5) return four_groups ((int)($players_count/4)); if ( ($players_count % 6 == 0) && (3<=$players_count/6) && ($players_count/6<=5) ) return groups_with_N_players ((int)($players_count/6), 6); if ($players_count % 3 == 0) return groups_with_N_players (3, (int)($players_count/3)); if ($players_count % 2 == 0 && $players_count<=12) return groups_with_N_players ((int)($players_count/2), 2); echo swiss_round ($players_count); } /* */ /* $ranking = ranking ($players_scores); var_dump ($ranking); echo "<br><br>"; */ $players_scores = [ [1,0], [2,0], [3,0], [4,0], [5,0], [6,0], [7,0], [8,0] ]; $max_players = 30; for ($i=0;$i<=$max_players;$i++) { echo $i." = "; $system = round_count_system ($i); echo "\n"; } function no_match ($players_count) { echo "No match!"; } function everybody_battles_everybody ($players_count) { echo "Every player battles the other players."; } function four_groups ($players_count) { echo "4 groups with ".$players_count." players each."; } function groups_with_N_players ($n, $players_count) { echo $players_count." "."groups with ".$n." players each."; } function swiss_round ($players_count) { echo "swiss system with "; echo floor (log ($players_count, 2))+1; echo " rounds. "; if ($players_count%2) echo "Some players play only ".floor (log ($players_count, 2))." matchs."; } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 4
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 4
Branch analysis from position: 14
Branch analysis from position: 4
filename:       /in/6c7uK
function name:  (null)
number of ops:  15
compiled vars:  !0 = $players_scores, !1 = $max_players, !2 = $i, !3 = $system
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   ASSIGN                                                   !0, <array>
   40     1        ASSIGN                                                   !1, 30
   41     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->12
   43     4    >   CONCAT                                           ~7      !2, '+%3D+'
          5        ECHO                                                     ~7
   44     6        INIT_FCALL                                               'round_count_system'
          7        SEND_VAR                                                 !2
          8        DO_FCALL                                      0  $8      
          9        ASSIGN                                                   !3, $8
   45    10        ECHO                                                     '%0A'
   41    11        PRE_INC                                                  !2
         12    >   IS_SMALLER_OR_EQUAL                                      !2, !1
         13      > JMPNZ                                                    ~11, ->4
   77    14    > > RETURN                                                   1

Function ranking:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6c7uK
function name:  ranking
number of ops:  20
compiled vars:  !0 = $players_scores, !1 = $players, !2 = $scores
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'array_column'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 0
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !1, $3
    6     6        INIT_FCALL                                               'array_column'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 1
          9        DO_ICALL                                         $5      
         10        ASSIGN                                                   !2, $5
    7    11        INIT_FCALL                                               'array_multisort'
         12        SEND_REF                                                 !2
         13        SEND_VAL                                                 3
         14        SEND_REF                                                 !1
         15        SEND_VAL                                                 4
         16        SEND_REF                                                 !0
         17        DO_ICALL                                                 
    8    18      > RETURN                                                   !0
    9    19*     > RETURN                                                   null

End of function ranking

Function round_system:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6c7uK
function name:  round_system
number of ops:  9
compiled vars:  !0 = $players_scores, !1 = $players_count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   13     1        INIT_DYNAMIC_CALL                                        !1
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
   14     4        INIT_FCALL_BY_NAME                                       'round_count_system'
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0  $3      
          7      > RETURN                                                   $3
   15     8*     > RETURN                                                   null

End of function round_system

Function round_count_system:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 22
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 46) Position 1 = 25, Position 2 = 28
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 35
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
2 jumps found. (Code = 46) Position 1 = 38, Position 2 = 41
Branch analysis from position: 38
2 jumps found. (Code = 46) Position 1 = 42, Position 2 = 45
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 53
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 63
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 63
2 jumps found. (Code = 46) Position 1 = 66, Position 2 = 68
Branch analysis from position: 66
2 jumps found. (Code = 43) Position 1 = 69, Position 2 = 76
Branch analysis from position: 69
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 76
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 68
Branch analysis from position: 45
Branch analysis from position: 41
Branch analysis from position: 28
filename:       /in/6c7uK
function name:  round_count_system
number of ops:  81
compiled vars:  !0 = $players_count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   19     1        IS_SMALLER                                               !0, 2
          2      > JMPZ                                                     ~1, ->7
          3    >   INIT_FCALL_BY_NAME                                       'no_match'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0  $2      
          6      > RETURN                                                   $2
   20     7    >   IS_SMALLER_OR_EQUAL                                      !0, 5
          8      > JMPZ                                                     ~3, ->13
          9    >   INIT_FCALL_BY_NAME                                       'everybody_battles_everybody'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0  $4      
         12      > RETURN                                                   $4
   21    13    >   IS_EQUAL                                                 !0, 8
         14      > JMPZ                                                     ~5, ->22
         15    >   INIT_FCALL_BY_NAME                                       'groups_with_N_players'
         16        SEND_VAL_EX                                              4
         17        DIV                                              ~6      !0, 4
         18        CAST                                          4  ~7      ~6
         19        SEND_VAL_EX                                              ~7
         20        DO_FCALL                                      0  $8      
         21      > RETURN                                                   $8
   22    22    >   MOD                                              ~9      !0, 4
         23        IS_EQUAL                                         ~10     ~9, 0
         24      > JMPZ_EX                                          ~10     ~10, ->28
         25    >   DIV                                              ~11     !0, 4
         26        IS_SMALLER_OR_EQUAL                              ~12     ~11, 5
         27        BOOL                                             ~10     ~12
         28    > > JMPZ                                                     ~10, ->35
         29    >   INIT_FCALL_BY_NAME                                       'four_groups'
         30        DIV                                              ~13     !0, 4
         31        CAST                                          4  ~14     ~13
         32        SEND_VAL_EX                                              ~14
         33        DO_FCALL                                      0  $15     
         34      > RETURN                                                   $15
   23    35    >   MOD                                              ~16     !0, 6
         36        IS_EQUAL                                         ~17     ~16, 0
         37      > JMPZ_EX                                          ~17     ~17, ->41
         38    >   DIV                                              ~18     !0, 6
         39        IS_SMALLER_OR_EQUAL                              ~19     3, ~18
         40        BOOL                                             ~17     ~19
         41    > > JMPZ_EX                                          ~17     ~17, ->45
         42    >   DIV                                              ~20     !0, 6
         43        IS_SMALLER_OR_EQUAL                              ~21     ~20, 5
         44        BOOL                                             ~17     ~21
         45    > > JMPZ                                                     ~17, ->53
   24    46    >   INIT_FCALL_BY_NAME                                       'groups_with_N_players'
         47        DIV                                              ~22     !0, 6
         48        CAST                                          4  ~23     ~22
         49        SEND_VAL_EX                                              ~23
         50        SEND_VAL_EX                                              6
         51        DO_FCALL                                      0  $24     
         52      > RETURN                                                   $24
   25    53    >   MOD                                              ~25     !0, 3
         54        IS_EQUAL                                                 ~25, 0
         55      > JMPZ                                                     ~26, ->63
         56    >   INIT_FCALL_BY_NAME                                       'groups_with_N_players'
         57        SEND_VAL_EX                                              3
         58        DIV                                              ~27     !0, 3
         59        CAST                                          4  ~28     ~27
         60        SEND_VAL_EX                                              ~28
         61        DO_FCALL                                      0  $29     
         62      > RETURN                                                   $29
   26    63    >   MOD                                              ~30     !0, 2
         64        IS_EQUAL                                         ~31     ~30, 0
         65      > JMPZ_EX                                          ~31     ~31, ->68
         66    >   IS_SMALLER_OR_EQUAL                              ~32     !0, 12
         67        BOOL                                             ~31     ~32
         68    > > JMPZ                                                     ~31, ->76
         69    >   INIT_FCALL_BY_NAME                                       'groups_with_N_players'
         70        DIV                                              ~33     !0, 2
         71        CAST                                          4  ~34     ~33
         72        SEND_VAL_EX                                              ~34
         73        SEND_VAL_EX                                              2
         74        DO_FCALL                                      0  $35     
         75      > RETURN                                                   $35
   27    76    >   INIT_FCALL_BY_NAME                                       'swiss_round'
         77        SEND_VAR_EX                                              !0
         78        DO_FCALL                                      0  $36     
         79        ECHO                                                     $36
   28    80      > RETURN                                                   null

End of function round_count_system

Function no_match:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6c7uK
function name:  no_match
number of ops:  3
compiled vars:  !0 = $players_count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
   51     1        ECHO                                                     'No+match%21'
   52     2      > RETURN                                                   null

End of function no_match

Function everybody_battles_everybody:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6c7uK
function name:  everybody_battles_everybody
number of ops:  3
compiled vars:  !0 = $players_count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   RECV                                             !0      
   56     1        ECHO                                                     'Every+player+battles+the+other+players.'
   57     2      > RETURN                                                   null

End of function everybody_battles_everybody

Function four_groups:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6c7uK
function name:  four_groups
number of ops:  5
compiled vars:  !0 = $players_count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   RECV                                             !0      
   61     1        CONCAT                                           ~1      '4+groups+with+', !0
          2        CONCAT                                           ~2      ~1, '+players+each.'
          3        ECHO                                                     ~2
   62     4      > RETURN                                                   null

End of function four_groups

Function groups_with_n_players:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6c7uK
function name:  groups_with_N_players
number of ops:  8
compiled vars:  !0 = $n, !1 = $players_count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   66     2        CONCAT                                           ~2      !1, '+'
          3        CONCAT                                           ~3      ~2, 'groups+with+'
          4        CONCAT                                           ~4      ~3, !0
          5        CONCAT                                           ~5      ~4, '+players+each.'
          6        ECHO                                                     ~5
   67     7      > RETURN                                                   null

End of function groups_with_n_players

Function swiss_round:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 24
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/6c7uK
function name:  swiss_round
number of ops:  25
compiled vars:  !0 = $players_count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   RECV                                             !0      
   71     1        ECHO                                                     'swiss+system+with+'
   72     2        INIT_FCALL                                               'floor'
          3        INIT_FCALL                                               'log'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 2
          6        DO_ICALL                                         $1      
          7        SEND_VAR                                                 $1
          8        DO_ICALL                                         $2      
          9        ADD                                              ~3      $2, 1
         10        ECHO                                                     ~3
   73    11        ECHO                                                     '+rounds.+'
   74    12        MOD                                              ~4      !0, 2
         13      > JMPZ                                                     ~4, ->24
         14    >   INIT_FCALL                                               'floor'
         15        INIT_FCALL                                               'log'
         16        SEND_VAR                                                 !0
         17        SEND_VAL                                                 2
         18        DO_ICALL                                         $5      
         19        SEND_VAR                                                 $5
         20        DO_ICALL                                         $6      
         21        CONCAT                                           ~7      'Some+players+play+only+', $6
         22        CONCAT                                           ~8      ~7, '+matchs.'
         23        ECHO                                                     ~8
   75    24    > > RETURN                                                   null

End of function swiss_round

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
183.14 ms | 1415 KiB | 22 Q