Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 3 123 LastLast
Results 1 to 15 of 35
  1. #1
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts

    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

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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?

  • #3
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    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
    Last edited by sonny; 11-12-2012 at 09:14 PM.

  • #4
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    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

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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?

  • #6
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    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
    the head as always,

    Sonny
    Last edited by sonny; 11-13-2012 at 08:49 PM.

  • #7
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    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(); 

  • #8
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    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
    Last edited by sonny; 11-13-2012 at 09:01 PM.

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Quote Originally Posted by poyzn View Post
    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.

  • #10
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    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
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    Quote Originally Posted by Fou-Lu View Post
    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(); 

  • #12
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    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 (); 
    Last edited by sonny; 11-13-2012 at 10:12 PM.

  • #13
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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.
    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.

  • #14
    Regular Coder sonny's Avatar
    Join Date
    Apr 2008
    Location
    United States
    Posts
    567
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    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

  • #15
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    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).


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •