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 9203089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:23:50+00:00 2026-06-17T23:23:50+00:00

I’m trying to make a sorting program to sort tournament matches. By entering names

  • 0

I’m trying to make a sorting program to sort tournament matches.

By entering names of contestant i want these to be sorted in a specific way. Criterias are that no person can go to matches after eachother, but everyone has to face eachother.

example:

1 - 2

1 - 3

1 - 4

1 - 5

2 - 3

2 - 4

2 - 5

3 - 4

3 - 5

4 - 5

These are all the matches and they have to be sorted/organized in such manner that no one as close as possible cannot be in matches after each other.

I know for a mathematical fact that it isn’t possible to solve so that everyone doesn’t go two matches after each other. But i want the “sorting” to be as close as possible.

It has to be a bit “smart” in that sense that it tries its best.
The sorting has to be dynamic so if i enter 7 contestants up to 30 contestants the sorting will try its best.

Right now i have the contestants either in the right order say 1-17 in an arraylist, or i have them in all the permutations in an arraylist like: 1, 2, 1, 3, 1, 4, 2, 3, 2, 4, 3, 4.

I have tried with comparing numbers, iterating in different ways but im dead in the water. Im asking for help, or someone that can point me in the right direction so i can turn

this:

1 - 2

1 - 3

1 - 4

1 - 5

2 - 3

2 - 4

2 - 5

3 - 4

3 - 5

4 - 5

to this:

5-4

1-2

3-4

1-5

2-3

1-4

2-5

3-1

5-4

3-5   <--here number 5 has to go 2 matches in a row
  • 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-17T23:23:51+00:00Added an answer on June 17, 2026 at 11:23 pm

    I propose a “random” solution to your pairings so that the contestants can’t predict their placement from year to year (assuming the event is annual).

    My solution starts by making the combinations of all pairings. The randomizer function swaps two random pairings.

    The “count-back-to-backs” function counts the number of pairings in which a contestant goes back to back. This is a metric … or criteria … that you judge the array of pairings by.

    The main loop runs a large number of randomizer loops and remembers the configuration with the fewest back-to-back contests. You can vary the number of loops.

    You can also add other functions to gather metrics about a particular set of pairings and keep/reject based on those metrics.

    This solution is thus: (1) generate random pairings and (2) keep/reject the array of pairings based on one or more criteria and (3) let the computer generate a large number of these random sets for your judgement.

    The output is the array of pairings with the number of back-to-backs on the end like

    [3 – 5, 2 – 4, 1 – 5, 2 – 3, 1 – 4, 2 – 5, 3 – 4, 1 – 2, 4 – 5, 1 – 3]0

    import java.util.ArrayList;
    import java.util.List;
    import java.util.Random;
    
    public class Contest {
    
    static Random rand = new Random();
    
    static class Pairing {
        int contestantA;
        int contestantB;
        public Pairing(int a, int b) {
            contestantA = a;
            contestantB = b;
        }
        public String toString() {
            return ""+contestantA+" - "+contestantB;
        }
    }
    
    static int countBackToBacks(List<Pairing> pairs) {
        int backs = 0;
        for(int x=0;x<pairs.size()-1;++x) {
            Pairing a = pairs.get(x);
            Pairing b = pairs.get(x+1);
            if(a.contestantA==b.contestantA || a.contestantA==b.contestantB || 
                    a.contestantB==b.contestantA || a.contestantB==b.contestantB)
            {
                ++backs;                
            }
        }           
    
        return backs;
    }
    
    static void randomize(List<Pairing> pairs) {
        int a = rand.nextInt(pairs.size());
        int b = rand.nextInt(pairs.size());
        Pairing pa = pairs.get(a);
        Pairing pb = pairs.get(b);
        pairs.set(a, pb);
        pairs.set(b, pa);       
    }
    
    public static void main(String [] args) {
    
        List<Pairing> pairs = new ArrayList<Pairing>();
        int numEntries = 5;//Integer.parseInt(args[0]);
        for(int x=0;x<numEntries-1;++x) {
            for(int y=x+1;y<numEntries;++y) {               
                Pairing p = new Pairing(x+1,y+1);
                pairs.add(p);               
            }
        }
    
        int bestVal = Integer.MAX_VALUE;
        String best = "";
        for(int x=0;x<1000000;++x) {
            randomize(pairs);
            int backs = countBackToBacks(pairs);
            if(backs<bestVal) {
                bestVal = backs;
                best = pairs.toString();
            }
        }
    
        System.out.println(best + bestVal);
    
    }   
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm interested in microtypography issues on the web. I want a tool to fix:

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.