1

I have 13 football matches with a possible results of Home Win , Draw , Away win. One has to predict all 13 games for a single bet. I have been trying to generate a script that can compute all possible bet combinations, mathematically, the number of possible matches is 3^13.

So far what I have is this in PHP;

    $count  = 1;
    $total_rows     = 13;
    $total_level    = 13;
    $total_cols     = 3;
    $total_global   = 3;

    $active_rows    = 0;
    $active_cols    = 0;
    $active_levels  = 0;
    $active_global  = 0;

    $betArray   = array();

    $aciveChoice[$total_rows]   = 0;
    $globalChoice[$total_level] = 0;

    while($active_rows < $total_rows){
        while($active_cols < $total_cols){

            while($active_global < $total_global){
                while($active_levels < $total_level){
                    echo $active_rows.' - '.$active_levels.': Select:'.$active_cols.' - '.$active_global.'<br/>';
                    $active_levels++;
                }
                echo $count++.'<br /><br /><br />';
                $active_levels  = 0;
                $active_global++;                       
            }

            $active_global = 0;
            $active_cols++;
        }
        $active_cols    = 0;
        $active_rows++; 
        }   
    }

My script is not giving all possible combinations. Any ideas on how to tackle this will be appreciated.

4
  • 4
    13^3? No, 3^13! Are you sure you want 1594323 rows on your web page? Commented Aug 30, 2018 at 10:06
  • @Amadan This is for analysis purpose and not for display. Commented Aug 30, 2018 at 10:13
  • Well, what do you want to do with 1594323 results? stuff them in a list? call a callback? Your code doesn't really give me a hint... Commented Aug 30, 2018 at 10:14
  • @Amadan for testing I am obviously not using 13. I am using 4 to test. I want to get the script right first then I will organize my code thereafter. The purpose of this is to create a decision support system for users based on history Commented Aug 30, 2018 at 10:18

1 Answer 1

1
$matches = 13;
$outcomes = 3;
$possibilities = $outcomes ** $matches;

for ($count = 0; $count < $possibilities; $count++) {
  echo str_pad(base_convert($count, 10, 3), $matches, '0', STR_PAD_LEFT)."\n";
}

This will print a number of 13-character strings, with three different possibilities for each character. (It is up to you to decide how to allocate meanings; I'd probably use 1 for Team1 win, 2 for Team2 win, 0 for draw.)

This will fail if you make the numbers too large, since base_convert works through float, apparently. There are ways around it, but if you're exploring that many possibilities you might have other problems :P

Sign up to request clarification or add additional context in comments.

1 Comment

This is perfect @Amadan . Exactly what I wanted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.