473,804 Members | 3,278 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating team match ups using unique combinations

2 New Member
I need to create unique team versus team match ups for tournaments that I hold.

For a given number of teams I need to find a given number games.

Example:

10 Teams 5 games each would mean each team would play games against 5 unique opponents.

I can load a table with unique combinations but struggle with the logic when it comes to picking each team's match ups. What happens is you run out of match ups when you loop through the table picking match ups because teams get used up in a linear fashion and by the time you reach the higher numbered teams there are not enough unique combos left.

As a human, I can recognize this, say in a spreadsheet, and anticipate it thus "saving" some earlier teams for match ups later.

Example:

1 vs. 2
1 vs. 3
1 vs. 4
1 vs. 9
1 vs. 10

Instead of:

1 vs. 2
1 vs. 3
1 vs. 4
1 vs. 5
1 vs. 6

So I am looking for help on how to search a table of match ups and selecting a given number for each team and having enough match ups for each team available.

Good luck and thanks in advance.
Apr 27 '11 #1
3 4131
ukfusion
35 New Member
Not sure if I fully understand.

Are you wanting to select them all in one go and arrange the match ups then? or save some for later and select them then?

If you're matching them all up in one go can you not store the matched values in an array so when you come to create your next matchup you know who has already been selected?

or if you want to store the matched values you could store them like
Team 1 - team 2 - game date
1 2 xx/xx/xxxx

Then count how many games that team has been matched on and use that to only query the ones that have games left to play?

you can always run a scheduled task to clear the table once you're done or something like that.

Sorry but im not 100% sure how you plan to implement it so its a bit hard to comment.....im not an sql expert either but seeing as how no one else had offered any suggestions though id have a go....im still waiting for a reply on my question with 60 views and no reply lol.
Apr 28 '11 #2
RonBon
2 New Member
Yes, I'm storing the match ups in a table.

What I have so far is I collect the number of desired teams and number of games for each team. 10 teams and 5 games each in this example.

I loop through and create a table of unique match ups regardless of the number of games.

It looks something like this:

Col 1 is Match
Col 2 is Home
Col 3 is Away

Table Data:
1v2 1 2
1v3 1 3
1v4 1 4
..

notice no 2v1 or 2v2, data validation before write to table eliminates these duplicates.

2v3 2 3
2v4 2 4
..
10v1 10 1
10v2 10 2
etc.

I know that based on the formula for unique combinations that I will end up with 45 unqiue combinations in my table.
N(N-1)/2 = 10(9)/2 = 45

What I now need to do is pick 5 of those combinations for each team with out any team having more than 5 games.

If I just pick the first 5 for each home team I will run out of vaild or non-duplicate choices for the higher numbered teams.

Cycling through and picking just one for each team in a round robin format does not work either.

The way I achieve it in a spreadsheet is to save matchups from one or more of the earlier home teams and use them as away teams in the later team's matchups, but I can't seem to find a calculation that will tell me how many to save.

"Forest for the Trees" maybe at this point.

Thanks for your reply
Apr 28 '11 #3
Rabbit
12,516 Recognized Expert Moderator MVP
Given a distinct source of teams, if you cross join it with itself and limit by the second table's team id being larger than the first table's team id, then you get a resulting set of unique combinations.

Expand|Select|Wrap|Line Numbers
  1. SELECT T1.TeamID, T2.TeamID
  2. FROM (SELECT DISTINCT TeamID FROM TeamTable) T1,
  3.      (SELECT DISTINCT TeamID FROM TeamTable) T2
  4. WHERE T2.TeamID > T1.TeamID
Now that you have a distinct list of matchups, creating a column of random numbers will allow you to select the matchups at random. Provided that you give RAND a proper seed.

Expand|Select|Wrap|Line Numbers
  1. SELECT T1.TeamID, T2.TeamID, RAND(((DATEPART(mm, GETDATE()) * 100000)
  2.     + (DATEPART(ss, GETDATE()) * 1000)
  3.     + DATEPART(ms, GETDATE()))
  4.     * T1.TeamID * T2.TeamID * (T1.TeamID + T2.TeamID)) AS R
  5. FROM TeamTable T1, TeamTable T2
  6. WHERE T2.TeamID > T1.TeamID
  7. ORDER BY R
With that key piece of information in place. The final step would just be to use a subquery to select the top 5 for each team.
Apr 28 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1600
by: Bob | last post by:
Why, in the process of creating a unique index, does SQL Server allow me to select the "Ignore duplicate keys" option? Wouldn't I just create a non-unique index if I wanted to ignore duplicate keys? I came across this fact while preparing for the SQL Server design exam.
12
10277
by: Niall Porter | last post by:
Right this has to be a Micro$oft mess-up surely...? I'm running SQL 2k standard with SP3. I have a table which I'm trying to query using a LIKE operator on a varchar field as follows .... WHERE dbo.tbl_pm_projects.SeniorManagerID LIKE '%' .... In actual fact the % is passed in by the application when the user
3
8029
by: Thomas McK | last post by:
Hi all, I'm not sure how to get around this, I was hoping someone could provide me with some help. Let's take this simple data set of 2 columns in a table: Tom - id1 Bob - id2 Jane - id1 John - id8 Fred - id2 John - id8
3
1346
by: codabill | last post by:
Can someone please refer me to books, articles, websites where I can obtain information on how to set up VS2003 for team development. I am a project manager for a non-trivial military software project that is migrating from ASP to ASP.NET. I have a team of 9 developers using VS2003. Of concern to me is that VS2003 compiles its projects into a single DLL. This will not work for our environment as our architecture is SOA based and as...
4
1998
by: Livin | last post by:
I need to dynamically create dictionary names using strings input at the time of creation. These will then be placed into a "Parent" dictionary. I'm new to python, and programming, so please bear with me. here's my initial thought but I don't think it will work... item='Kitchen Ceiling Lights' devDictName = item.replace(' ','+') 'dict_'+devDictName = , 'Status':item,
1
7445
by: New Guy | last post by:
Newby question... When I try to create an array using this method... value = buffer = Array.new(10) {value} I get an array of references to the single instance of "value". But I want an array of unique objects. How should I be specifying this? Thanks...
3
2290
by: hendedav | last post by:
Gang, I have been working on this for a few hours and am frustrated beyond all extent. I have tried to research this on the web as well with no success. I am trying to match certain contents within a wrapper div. So for example if the inside of the wrapper div was the following: <div id="wrapper"> <a href="#">a great link that contain text and symbols</a>
3
2271
by: femina | last post by:
heres a sample program #include<iostream> using namespace std; void add(...) { cout<<"match using ellipsis"; } void add(int a,int b) { cout<<"a and b are"<<a<<b;
11
7183
by: breal | last post by:
I have three lists... for instance a = ; b = ; c = ; I want to take those and end up with all of the combinations they create like the following lists
5
3743
by: ravysters | last post by:
hi.. i am creating a .dll file from an object file using gcc... i want to create a shared library... i want to use the dll to implement a new functionality.. but when i compile the file for creating the dll i get the following errors.. Cannot export .idata$4: symbol not found Cannot export .idata$5: symbol not found Cannot export .idata$6: symbol not found Cannot export .text: symbol not found Cannot export ⌂postgres_NULL_THUNK_DATA:...
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9582
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10580
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10082
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5652
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2993
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.