Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8701857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:30:17+00:00 2026-06-13T02:30:17+00:00

For one project, I need to compute matchs planning between several teams. Requirement: I’ve

  • 0

For one project, I need to compute matchs planning between several teams.

Requirement:

  • I’ve a pair number of teams
  • All teams have to play against every other team once(and only once)
  • All team plays at the same time

E.g.
With 4teams(A,B, C and D), I would like to be able to compute this:

Round 1

  • A vs B
  • C vs D

Round 2

  • A vs D
  • B vs C

Round 3

  • A vs C
  • B vs D

The problem is that, there is some choice in round X which will make impossible any match in round X+1(teams have already played against other teams).

I think I can use some backtracking technique, but I’m searching if there is an algorithm for this?

This will be implemented in c#.

Have you any idea about how to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:30:18+00:00Added an answer on June 13, 2026 at 2:30 am

    Try round-robin. This is a simple scheduling algorithm to share timeslots among processes, but this problem reminds me it somehow.

    EDIT

    Now here is an implementation of Round-robin tournament. If we have ODD number of teams, we must insert a dummy team, otherwise there would be a team without opponent. As number of rounds are EVEN, number of total rounds are (NumberOfTeams-1). At the very beginning we set-up the first round:

    A B C D E F G H

    H G F E D C B A

    So, Team A – H, Team B – G, etc.

    From now, we keep one team fixed, for instance A. Then we shift A_Side teams from the 2nd position to the right. The last team will come into position 2. ( A B C D E F G H will be A H B C D E F G). See rotate_A_side() recursive method (just for fun).

    The half of the B_Sides are shifted left. This will make H G F E D – G F E D.

    As team selection is symmetric (A plays with H, then H plays wiht A), the upper half of B_Side is the reverse copy of the A_Side low part teams. So, D C B A will be C B H A). See rotate_B_side().

    So, Round 2 is:

    A H B C D E F G

    G F E D C B H A

    To give all rounds, simply repeat the aforementioned shifting steps. See NextRound()

    Here is a c# class which implements the algorithm:

        class Teams
    {
        private int[] A_Side;
        private int[] B_Side;
        public int[,] PlayingCounter;
        public int RoundCounter = 1;
        public bool DummyTeam = false;                 // ODD number of teams -> one team will no be able to play.
    
        public bool NextRoundExists
        {
            get
            {
                return (RoundCounter < B_Side.Length-1);
    
            }
        }
        public Teams(int NumberOfTeams)
        {
            if (NumberOfTeams % 2 != 0)
            {
                NumberOfTeams++; DummyTeam = true;
            }
            A_Side = new int[NumberOfTeams];
            B_Side = new int[NumberOfTeams];
            PlayingCounter = new int[NumberOfTeams,NumberOfTeams];     // Counting to see if alg is correct
            int x,y;
            for (x=0; x<NumberOfTeams; x++) 
            {
                A_Side[x] = x + 1;                  
                B_Side[NumberOfTeams-x-1]=x+1; 
                for (y=0;y<NumberOfTeams;y++) 
                {
                    PlayingCounter[x,y] = 0;
                }
    
            }
    
        }
    
        private void rotate_A_Side(int AtPos)
        {
            if (AtPos == 1)
            {
                int iO = A_Side[A_Side.Length - 1];
                rotate_A_Side(AtPos+1);
                A_Side[1] = iO;
            }
            else 
            {
                if (AtPos < A_Side.Length - 1) { rotate_A_Side(AtPos + 1); }
                A_Side[AtPos] = A_Side[AtPos - 1];
            }
        }
        public void rotate_B_Side()
        {
            int i;
            for (i = 0; i<B_Side.Length/2 ; i++)
            {
                B_Side[i] = B_Side[i + 1];
            }
            for (i = B_Side.Length / 2; i < B_Side.Length; i++)
            {
                B_Side[i] = A_Side[B_Side.Length/2 - (i -B_Side.Length/2 + 1) ];
            }
    
        }
        public bool NextRound()
        {
            if (NextRoundExists)
            {
                RoundCounter++;         // Next round
                rotate_A_Side(1);       // A side rotation
                rotate_B_Side();        // B side rotation
                LogRound();             // Update counters
                return true;
            }
            else return false;
        }
        public void LogRound()
        {
            for (int x = 0; x < A_Side.Length; x++)
            {
                PlayingCounter[A_Side[x]-1, B_Side[x]-1]++;
                PlayingCounter[B_Side[x]-1, A_Side[x]-1]++;
            }
        }
        public string GetCounters()
        {
            string return_value = "";
    
            for (int y = 0; y < A_Side.Length; y++)
            {
                for (int x = 0; x < A_Side.Length; x++)
                {
                    return_value += String.Format(" {0:D3}", PlayingCounter[y, x]);
                }
                return_value += System.Environment.NewLine;
            }
            return return_value;
        }
    
        public string GetCurrentRound()
        {
            string Round = "Round #" + RoundCounter.ToString() + " ";
            for (int x = 0; x < B_Side.Length; x++)
            {
                Round += String.Format("Team {0} - Team {1};", A_Side[x], B_Side[x]);
            }
            return Round;
        }
    
    }
    

    From your code, you can use it like:

    Teams Rounds = new Teams(22);
    if (Rounds.DummyTeam) { 
           // Anything to do if nober of teams is odd?
    }
    Rounds.LogRound();    // DEBUG - you can check number of matches ;-)
    while (Rounds.NextRoundExists)     // While we have next round...
     {
       Rounds.NextRound();             // ... generate the next 
                                       //     round (team assignment)
       // Your can tack using: Rounds.GetCurrentRound()
     }
    // If you want to see the number of matches, call Rounds.GetCounters();
    

    6 Teams gave me the following output:

    Round #1 A-F ; B-E ; C-D ; D-C ; E-B ; F-A ;

    Round #2 A-E ; F-D ; B-C ; C-B ; D-F ; E-A ;

    Round #3 A-D ; E-C ; F-B ; B-F ; C-E ; D-A ;

    Round #4 A-C ; D-B ; E-F ; F-E ; B-D ; C-A ;

    Round #5 A-B ; C-F ; D-E ; E-D ; F-C ; B-A ;

    I replaced Team 1 with A, etc.

    rotate_B_Side() should be refined, this is a quick approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need to have one project on asp.net mvc 1 but i want to
I have a project on one computer that I need to work on another
Actually in one of my project i need to read images from remote server
I am working on one project where there is a functionality need to implement
I need to build a solution, but exclude one project. How should I do
I currently have one project that currently contains multiple packages. These packages make up
I have one project inside that I have SqlServerFunctions in test.cs file. code: [Microsoft.SqlServer.Server.SqlFunction]
I have two projects.One project is build in MVC asp.net and the other project
I have one project with is developed in Php and javascript. How to open
For one of my opensource projects, i need to compute the decimal equivalent of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.