Solved

Generating a schedule with 30 teams

Posted on 2004-09-21
4
317 Views
Last Modified: 2010-04-17
Hello

Im asking this question here (and not in the Math/Science section) because i need the code (i would prefer Java or C/C++) that will generate a sport team schedule following these rules:

case a:
- There are 30 teams
- Each teams playing 1 time against all other team (so 29 games per team)
- Cannot play twice against the same team
- Schedule must be random (if schedule is twice in a row, the results will differ)

case b:
- There are 30 teams
- Each teams playing 2 times against all other team (so 58 games per team)
- Schedule must be random (if schedule is twice in a row, the results will differ)

Big thanks to all who will try to help me out here.
Thanks

    -Oli
0
Comment
Question by:oroussea
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 125 total points
ID: 12112443
#include <stdlib.h>
char *teams[]={"team1", "team2", "team3", "team4", "team5", "team6", "team7", "team8", "team9", "team10", "team11", "team12", "team13", "team14", "team15", "team16", "team17", "team18", "team19", "team20", "team21", "team22", "team23", "team24", "team25", "team26", "team27", "team28", "team29", "team30"};
char *games[15];
void shuffle(char *array[],int n){
  int i;
  for( i=n; --i; ){
    int j = rand() % (i+1);
    char *t = array[i];
    array[i] = array[j];
    array[j] = t;    
  }
}
main(){
  int r,s,t;
  for( s=0;s<15; s+=1 ){ games[s] = (char *)malloc(20); }
  srand(time());
  printf("a\n");
  shuffle(teams,30);
  for( r=0;r<29;r++ ){
    for( s=0;s<15;s++ ){
      sprintf(games[s],"%s vs. %s",teams[s?(r+s-1)%29+1:0],teams[(28-s+r)%29+1]);
    }
    shuffle(games,15);
    for( s=0;s<15;s++ ){
      printf("%s\n",games[s]);
    }
    printf("\n");
  }
  printf("b\n");
  shuffle(teams,30);
  for( r=0;r<29;r++ ){
    for( s=0;s<15;s++ ){
      sprintf(games[s],"%s vs. %s",teams[s?(r+s-1)%29+1:0],teams[(28-s+r)%29+1]);
    }
    shuffle(games,15);
    for( s=0;s<15;s++ ){
      printf("%s\n",games[s]);
    }
    printf("\n");
  }
}
0
 

Author Comment

by:oroussea
ID: 12112619
Thanks for the quick reply ozo

But i dont see any diff between A and B...

But A seems to do it...

Thanks

  -Oli
0
 
LVL 84

Expert Comment

by:ozo
ID: 12116490
Isn't case b just case a repeated?
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 12118384
With the second shuffle of the teams the second half schedule should be different from the first half.

That should work unless you want it to be possible for teams 1 & 2 to be able to play back to back games or twice at any time in the season rather than once in the first 29 games and the second game in the last 29 games.

mlmcc

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
bunnyEars challenge 6 102
Exe program is not a valid Win 32 application 15 106
oracle query help 18 99
Auto-indent certain lines in Notepad++ 10 32
RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now