Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = <<<END
- Koalas
- Platypi
- Bilbies
- Thylacines
- Wallaroos
- END;
- //There are n-1 rounds
- $input = explode("\n", $input);
- $count = count($input);
- $always_first = array_shift($input);
- //var_dump($input);
- if($count%2){
- //if there is an even amount of teams
- //If there is an odd amount of teams
- $input[] = "bye";
- $count++;
- for($x = 0; $x < $count-1; $x++){
- //This loop is for each round
- //there is another for for echoing (n+1)/2 lines of draw
- $out = $x+1;
- echo "Round $out:\n";
- for($y = 0; $y < ($count+1)/2-1; $y++){
- //alway first vs input[last]
- //2 vs input[last-1]
- //3 vs input[last-y]
- $first = $input[$y-1];
- $second = $input[$count-$y-2];
- if($y == 0){
- if(end($input) == 'bye'){
- echo str_pad($always_first, 12, ' ', STR_PAD_RIGHT).end($input)."\n";
- }else{
- echo str_pad($always_first, 12, ' ', STR_PAD_RIGHT)."vs ".end($input)."\n";
- }
- }elseif($first == 'bye' || $second == 'bye'){
- if($first == 'bye'){
- echo str_pad($second, 12, ' ', STR_PAD_RIGHT).$first."\n";
- }else{
- echo str_pad($first, 12, ' ', STR_PAD_RIGHT).$second."\n";
- }
- }else{
- echo str_pad($first, 12, ' ', STR_PAD_RIGHT)."vs ".$second."\n";
- }
- }
- //rotate array counter clockwise
- array_unshift($input, array_pop($input));
- //var_dump($input);
- }
- }else{
- //if there is an even amount of teams
- //If there is an odd amount of teams
- //$input[] = "bye";
- for($x = 0; $x < $count-1; $x++){
- //This loop is for each round
- //there is another for for echoing (n+1)/2 lines of draw
- $out = $x+1;
- echo "Round $out:\n";
- for($y = 0; $y < ($count+1)/2-1; $y++){
- //alway first vs input[last]
- //2 vs input[last-1]
- //3 vs input[last-y]
- $first = $input[$y-1];
- $second = $input[$count-$y-2];
- if($y == 0){
- echo str_pad($always_first, 12, ' ', STR_PAD_RIGHT)."vs ".end($input)."\n";
- }else{
- echo str_pad($first, 12, ' ', STR_PAD_RIGHT)."vs ".$second."\n";
- }
- }
- //rotate array counter clockwise
- array_unshift($input, array_pop($input));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment