Schedule function help needed

Show 40 post(s) from this thread on one page
Page 1 of 3 123 Last
• 11-12-2012, 06:37 PM
sonny
Schedule function help needed
Hi I am a volunteer youth coach trying to create a function that
will automatically create a team vs team schedule, any odd number
team would get a bye if needed.

PHP Code:

``` \$NumberOfGames = 10;//testing \$NumberOfTeams = 12; //testing function Schedule(\$NumberOfGames, \$NumberOfTeams) { // I have been trying a while to get this, nothing works correctly // I don't understand  how push can help do this?. echo \$schedule; } Schedule(\$NumberOfGames, \$NumberOfTeams);  ```
Thanks
Sonny
• 11-12-2012, 07:07 PM
Fou-Lu
There isn't anywhere near enough information here. What are the rules for selection of games? I assume that its always one team versus another team, but what rules drive whom plays whom? Does a schedule adjust based on wins and losses?
• 11-12-2012, 10:05 PM
sonny
Quote:

Originally Posted by Fou-Lu
There isn't anywhere near enough information here. What are the rules for selection of games? I assume that its always one team versus another team, but what rules drive whom plays whom? Does a schedule adjust based on wins and losses?

Hi, No all teams play against each other the same amount of times over a 10 game
schedule, that's why I am having a hard time with it. I need to use functions I never used
before like pop push etc

what I want to do in theory is really simple, but the coding seems really hard
at least for me.

in the example below for simplicity sake

8 teams play each other over a 10 game schedule that's it, should I have a odd team
they would simply get a bye for that week that's about it.

I would need an array to feed the teams but am not sure what type would be best
because I don't know what built in php functions to use that might accomplish this.
\$TeamNames = "team1","team2","team3","team4,"team5","team6,"team7","team8";

the function result should be something like
team1 vs Team9
team5 vs team7
team 2 vs team6
team3 vs team4

Week 1 example and so on for week two

in summery I want to create a simple 10 week schedule ( That's 1 game a week)
where 8 teams play against each other the same amount of times. if I have a odd
number of teams provide a bye if needed.

Thanks
Sonny
• 11-13-2012, 07:24 PM
sonny
Fou or Anybody? I really need some help with this one
I explained things as clearly as humanly possible.

I need to create a schedule for 8 teams playing each
other for a span of 10 weeks, (that's 10 games each total)

thanks
Sonny
• 11-13-2012, 08:56 PM
Fou-Lu
So you need a combination based on team count x? That won't equate to 10; if you have 8 teams playing that would equate to. . . 28. Wait is that right?
(8!/(8-2)!)*1/(2!) = 40320/720 * 0.5 = 56 * 0.5 or 28. Yeah, so at 8 teams in order to play ever other team you would require 28 weeks, not 10. To get the 10, you would need exactly 5 teams, so you'd have these combinations:
Code:

```array (   0 =>   array (     0 => 1,     1 => 5,   ),   1 =>   array (     0 => 1,     1 => 4,   ),   2 =>   array (     0 => 1,     1 => 3,   ),   3 =>   array (     0 => 1,     1 => 2,   ),   4 =>   array (     0 => 2,     1 => 5,   ),   5 =>   array (     0 => 2,     1 => 4,   ),   6 =>   array (     0 => 2,     1 => 3,   ),   7 =>   array (     0 => 3,     1 => 5,   ),   8 =>   array (     0 => 3,     1 => 4,   ),   9 =>   array (     0 => 4,     1 => 5,   ), )```
So how do we modify the ruleset to accommodate the 10 weeks instead of the 28? Whom doesn't play whom, and how do we determine that?
• 11-13-2012, 09:46 PM
sonny
I said in my post above if there is a odd number team just give it a bye?
but I'm not even talking about that since I have 8 teams in my example?
I can't explain things any better or clearer then I have.

its really simple in theory, I don't get what your saying its not that complex
or confusing.

I have 8 teams in the league, each team plays a total of 10 games,
(that's equivalent to a 10 week schedule)

I'm just looking to create a simple basic schedule where they play against each
other that's all there is to it, nothing else to compute or think off.

I have been at this on and off for over 2 months now, that's why I tried to get
help here. when someone explains how to do this I will most likely slap myself in

Sonny
• 11-13-2012, 09:49 PM
poyzn
PHP Code:

``` function schedule(\$teams = 10) {   \$output = '<table cellpadding="5" border="1">';   for(\$i=1; \$i<=\$teams; \$i++) {     \$output .= '<tr>';       for(\$j=1; \$j<=\$teams; \$j++) {          \$output .= '<td>';           if(\$i == \$j) {             \$output .= ' - ';           } else {             \$output .= "team \$i vs. team \$j";           }              \$output .= '</td>';       }     \$output .= '</tr>';   }   \$output .= '</table>';   return \$output; } print schedule();  ```
• 11-13-2012, 09:54 PM
sonny
Thanks man, I will try that ASAP, that appears to be exactly what I need to do
guess I will pass the team names to schedule with a array. do you know the best
way to do this within the function?

something like
PHP Code:

``` \$teams= 'team1','team2,'team3','team4','team5','team6','team7','team8';  ```
Thanks
Sonny
• 11-13-2012, 09:58 PM
Fou-Lu
Quote:

Originally Posted by poyzn
PHP Code:

``` function schedule(\$teams = 10) {   \$output = '<table cellpadding="5" border="1">';   for(\$i=1; \$i<=\$teams; \$i++) {     \$output .= '<tr>';       for(\$j=1; \$j<=\$teams; \$j++) {          \$output .= '<td>';           if(\$i == \$j) {             \$output .= ' - ';           } else {             \$output .= "team \$i vs. team \$j";           }              \$output .= '</td>';       }     \$output .= '</tr>';   }   \$output .= '</table>';   return \$output; } print schedule();  ```

This has repetition in it. I'm under the impression repetition is not desired, so 1 should play 2 only once. That's easy to accommodate though.

Perhaps I'm still not "getting it" here. I still see that if you had 8 teams it would equate to 28 games played, not 10 (9 teams would be 36, 10 would be 45, etc). I'm not sure how you intend to shove the 8 teams into a 10 week period.
• 11-13-2012, 10:08 PM
sonny
Quote:

Originally Posted by Fou-Lu
This has repetition in it. I'm under the impression repetition is not desired, so 1 should play 2 only once. That's easy to accommodate though.

Perhaps I'm still not "getting it" here. I still see that if you had 8 teams it would equate to 28 games played, not 10 (9 teams would be 36, 10 would be 45, etc). I'm not sure how you intend to shove the 8 teams into a 10 week period.

Fou, 8 teams are playing a game against each other, every Sunday for 10 weeks
yes eventually they will be playing against each 5 times over 40 games.

every team will play 10 games, there will be 4 games played every Sunday
for a total of 40 games overall.

Sonny
• 11-13-2012, 10:10 PM
poyzn
Quote:

Originally Posted by Fou-Lu
This has repetition in it.

It can be easily fixed:

PHP Code:

``` function schedule(\$teams = 10) {   \$output = '<table cellpadding="5" border="1">';   for(\$i=1; \$i<\$teams; \$i++) {     \$output .= '<tr>';       for(\$j=2; \$j<=\$teams; \$j++) {          \$output .= '<td>';           if(\$i >= \$j) {             \$output .= ' - ';           } else {             \$output .= "team \$i vs. team \$j";           }              \$output .= '</td>';       }     \$output .= '</tr>';   }   \$output .= '</table>';   return \$output; } print schedule();  ```
• 11-13-2012, 10:48 PM
sonny
This function does not give a schedule correctly.

PHP Code:

``` function schedule(\$teams = 10) {   \$output = '<table cellpadding="5" border="1">';   for(\$i=1; \$i<\$teams; \$i++) {     \$output .= '<tr>';       for(\$j=2; \$j<=\$teams; \$j++) {          \$output .= '<td>';           if(\$i >= \$j) {             \$output .= ' - ';           } else {             \$output .= "team \$i vs. team \$j";           }              \$output .= '</td>';       }     \$output .= '</tr>';   }   \$output .= '</table>';   return \$output; } print schedule(); schedule ();  ```
• 11-13-2012, 11:44 PM
Fou-Lu
Wait step back a step here.
Assuming we have 8 teams in total yes? So we have each team playing 10 games; where do the extra 3 games per team come from (shared over multiple teams of course, so that's. . . 1.5 average I guess)? With only 8 teams in total to play, each team would only require a total of 7 games to play against (hence the 28 total game play for the number of combinations).
Is it just round robin on it? Lets only focus on team 1.
Quote:

Sunday # | Playing
1 | 2
2 | 3
3 | 4
5 | 6
7 | 8
8 | 2
9 | 3
10 | 4
The part that has me baffled as to how to deal with it is the remaining days beyond the permutation count for the number of teams. So with the above, we cap out on the 7th day, so I don't know how to make up the additional three days.

So the best way I can describe my conundrum here: I can easily calculate and generate the 28 required permutations. But I can't figure out how to match it to a ruleset of 4 per week for 10 weeks (which accounts for 40 games total) which is 12 above the original combination options (or 1.5x per team avg), some teams will need to play multiple other teams (up to 3x) repetition, but I don't know how to select which teams should be doing that.
• 11-14-2012, 12:16 AM
sonny
Quote:

Originally Posted by Fou-Lu
Wait step back a step here.
Assuming we have 8 teams in total yes? So we have each team playing 10 games; where do the extra 3 games per team come from (shared over multiple teams of course, so that's. . . 1.5 average I guess)? With only 8 teams in total to play, each team would only require a total of 7 games to play against (hence the 28 total game play for the number of combinations).
Is it just round robin on it? Lets only focus on team 1.

The part that has me baffled as to how to deal with it is the remaining days beyond the permutation count for the number of teams. So with the above, we cap out on the 7th day, so I don't know how to make up the additional three days.

So the best way I can describe my conundrum here: I can easily calculate and generate the 28 required permutations. But I can't figure out how to match it to a ruleset of 4 per week for 10 weeks (which accounts for 40 games total) which is 12 above the original combination options (or 1.5x per team avg), some teams will need to play multiple other teams (up to 3x) repetition, but I don't know how to select which teams should be doing that.

Hi Just trying to create a function where I enter the number of teams, and the number of
games to play, and the function simply creates a schedule, again if I have a odd number of
teams, it gives a team the bye if needed. that's about it.

Sonny
• 11-14-2012, 12:33 AM
Fou-Lu
Yes, I'm aware of what you want to do. What I'm saying is with 8 teams you cannot play a total of 40 games without partial repetition. So my question is still how to deal with which combinations are chosen for repetition. So I can only write combinations which apply to 7 games per team; that is one team plays every other team once and only once (28 games). If you played 56 total games (repetition allowed), then you could do it evenly with the 8, but not with 40.
The only way to get to the 40 with 8 teams really is to make it so every team only plays a total of 5 games. But again, that creates a problem since you still need to decide which two teams each team will not play against (each team needs to play 7 in order to play completely against each other).
Show 40 post(s) from this thread on one page
Page 1 of 3 123 Last