Last active
April 10, 2019 15:23
-
-
Save Cleanse/112b5b6a14c5c606b7a8bd249a79e274 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Pool 1: Rank 1, 8, 9, 16, 17 | |
* Pool 2: Rank 2, 7, 10, 15 | |
* Pool 3: Rank 3, 6, 11, 14 | |
* Pool 4: Rank 4, 5, 12, 13 | |
*/ | |
function seed_partition(array $teams, $groups = 1) | |
{ | |
$teamCount = count($teams); | |
$seeds = range(1, $teamCount); | |
$seeds = array_chunk($seeds, $groups); | |
$g = 1; | |
$orderedList = []; | |
foreach ($seeds as $chunk) { | |
if ($g % 2 === 0) { | |
$chunk = array_reverse($chunk); | |
} | |
foreach ($chunk as $item => $value) { | |
$orderedList[] = $value; | |
} | |
$g++; | |
} | |
$divisions = []; | |
$r = 1; | |
foreach ($orderedList as $seed) { | |
$divisions[$r][] = $seed; | |
if ($r % $groups !== 0) { | |
$r++; | |
} else { | |
$r = 1; | |
} | |
} | |
return $divisions; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment