Tournament bracket placement algorithm

前端 未结 10 646
生来不讨喜
生来不讨喜 2020-12-02 09:37

Given a list of opponent seeds (for example seeds 1 to 16), I\'m trying to write an algorithm that will result in the top seed playing the lowest seed in that round, the 2nd

10条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 10:15

    I've come up with the following algorithm. It may not be super-efficient, but I don't think that it really needs to be. It's written in PHP.

     0) {
    
                $out = array_merge($out, array_splice($players, 0, $splice));
                $out = array_merge($out, array_splice($players, -$splice));
    
            }            
    
            $players = $out;
        }
    
        // Print match list.
        for ($i = 0; $i < $count; $i++) {
            printf('%s vs %s
    %s', $players[$i], $players[++$i], PHP_EOL); } ?>

提交回复
热议问题