Jump to content


Photo

pairs


  • Please log in to reply
2 replies to this topic

#1 chriscloyd

chriscloyd
  • Members
  • PipPipPip
  • Advanced Member
  • 489 posts
  • LocationArizona

Posted 13 May 2006 - 05:13 AM

okay say i got 40 teams i wanna learn how to write the script where it randomly pairs two teams up to eachother 8 times but 8 dif teams not the same team as it paired up to b4 can someone help me? and then i want it to post into a table or file
44 bugs in my java code
44 bugs in my java code
Fix 1 bug, and complie again
122 bugs in my java code

#2 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 13 May 2006 - 07:28 AM

[!--quoteo(post=373420:date=May 13 2006, 12:13 AM:name=chriscloyd)--][div class=\'quotetop\']QUOTE(chriscloyd @ May 13 2006, 12:13 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
okay say i got 40 teams i wanna learn how to write the script where it randomly pairs two teams up to eachother 8 times but 8 dif teams not the same team as it paired up to b4 can someone help me? and then i want it to post into a table or file
[/quote]

This will get you two random id's from a table:
SELECT team_id FROM table1 WHERE ORDER BY RAND() LIMIT 2;

The rest of your question I don't understand. Try using proper centences.

#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 13 May 2006 - 07:44 AM

while i do understand your question, please note that we are not here to write your code for you. you need to make an effort to write your own code, and we will help you fix bugs....

HOWEVER... since I was extremely bored, I decided to do it anyways. Merry Christmas.

<?php

//generic array holding 40 values
$list = array('one','two','three','four','five',
              'six','seven','eight','nine','ten',
                            'eleven','twelve','thirteen','fourteen','fifteen',
                            'sixteen','seventeen','eighteen','nineteen','twenty',
                            'twentyone','twentytwo','twentythree','twentyfour','twentyfive',
                            'twentysix','twentyseven','twentyeight','twentynine','thirty',
                            'thirtyone','thirtytwo','thirtythree','thirtyfour','thirtyfive',
                            'thirtysix','thirtyseven','thirtyeight','thirtynine','fourty');

$max = 39; //starting amount of items (0-39 = 40)                            

// since you have 40 items you want to pair off, we will 
// do the 'pair-off 20 times
for ($count = 0;$count <20; $count++) {
   //pick 2 random items from the list 
     //and remove them from the list
     for ($number = 0; $number < 2; $number++) {
      $randompick = rand(0,$max);
        $numberpair[$number] = $list[$randompick];
        unset($list[$randompick]);
         $list = array_values($list);
        $max--;
   }
     //make a list of the items paired up
     $pairups[] = array('first' => $numberpair[0],
                        'second' => $numberpair[1]);
}

//generic printout of the list
$listofpairs = "<table border='1'><tr>";
$listofpairs.= "<td><b>First</b></td><td><b>Second</b></td></tr>";
for ($pairs = 0; $pairs < 20; $pairs++) {
   $listofpairs.="<tr>";
     foreach ($pairups[$pairs] as $val) {
      $listofpairs.="<td>" . $val . "</td>";
     }
     $listofpairs.="</tr>";
}
$listofpairs.="</table>";

echo $listofpairs;

?>

if you have your items in a database then you would select them the way you normally would and replace the $list array with an array of the values pulled from the database.

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users