How to resolve the algorithm Round-robin tournament schedule step by step in the Ada programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Round-robin tournament schedule step by step in the Ada programming language
Table of Contents
Problem Statement
A round-robin tournament is also known as an all-play-all-tournament; each participant plays every other participant once. For N participants the number of rounds is N-1 if N is an even number. When there are an odd number of participants then each round one contestor has no opponent (AKA as a "bye"). The number of rounds is N in that case. Write a program that prints out a tournament schedule for 12 participants (represented by numbers 1 to 12).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Round-robin tournament schedule step by step in the Ada programming language
Source code in the ada programming language
-- Create a round-robin schedule
-- J. Carter 2023 May
-- Circle method
with Ada.Text_IO;
procedure Round_Robin is
type Player_ID is range 1 .. 12;
type Player_List is array (Player_ID) of Player_ID;
Circle : Player_List;
J : Player_ID;
begin -- Round_Robin
Fill : for I in Circle'Range loop
Circle (I) := I;
end loop Fill;
All_Rounds : for Round in 1 .. Player_ID'Last - 1 loop
Ada.Text_IO.Put_Line (Item => "Round" & Round'Image);
J := Player_ID'Last;
Pairs : for I in 1 .. Player_ID'Last / 2 loop
Order : declare
Min : constant Player_ID := Player_ID'Min (Circle (I), Circle (J) );
Max : constant Player_ID := Player_ID'Max (Circle (I), Circle (J) );
begin -- Order
Ada.Text_IO.Put_Line (Item => Min'Image & " v" & Max'Image);
J := J - 1;
end Order;
end loop Pairs;
Ada.Text_IO.New_Line;
Circle := Circle (Circle'First) & Circle (Circle'Last) & Circle (Circle'First + 1 .. Circle'Last - 1);
end loop All_Rounds;
end Round_Robin;
You may also check:How to resolve the algorithm Fibonacci sequence step by step in the Wart programming language
You may also check:How to resolve the algorithm Ackermann function step by step in the Ursala programming language
You may also check:How to resolve the algorithm Trigonometric functions step by step in the Julia programming language
You may also check:How to resolve the algorithm Sorting algorithms/Heapsort step by step in the C++ programming language
You may also check:How to resolve the algorithm File modification time step by step in the FutureBasic programming language