Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only

PI Day 2019 : let's help André

  • 1.  PI Day 2019 : let's help André

    Posted 03/14/19 09:59 AM

    Hi,

     

    last year (2018) for PI Day (March 14th) , I posted

    Puzzles : having fun and useful mathematics

    where I mentioned some challenges:

    - The IBM ponder this challenge

    - The mathematical games (33rd year in 2019)

     

    Today is PI day again. March 14th 2019. So let me share a puzzle I enjoyed  that was in that later game recently.

     

     

     

    For those who do not speak French or German yet, let me translate into English:

     

    André, said Dede, has six identical dice.Each of them has the number 1 on one side, the number 2 on two sides and the number 3 on three sides.Dede rolls his six dice, what idea! What is the probability for the total points presented by the six dice equals 12?

    I used to like this kind of challenges 30 years ago and I still do.

     

    This is a combinatorics problem and the denominator is 6 power 6 for sure.

    The numerator is a good example of combinations :

    C(3,6)*3^3 + C(2,6)*C(2,4)*3^2*2^2+C(2,6)*2*3*2^4+2^6

    Which makes 5284 / 46656

    Then since I like OPL I tried to check my result with OPL: double checking never hurts!

     

    A naïve model:

     

    int pos[1..6]=[1,2,2,3,3,3];
     
     int res[a in 1..6][b in 1..6][c in 1..6][d in 1..6][e in 1..6][f in 1..6]=
     pos[a]+pos[b]+pos[c]+pos[d]+pos[e]+pos[f];
     
    tuple t
     {
     int a;
     int b;
     int c;
     int d;
     int e;
     int f;
     }


     
     int nbSol=count(res,12);
     
     
     execute
     {

     writeln("probability = ",nbSol," / ",Math.pow(6,6));
     }

    gives

     

    probability = 5284 / 46656

     

    but this only relies on the modeling part of OPL, not the solving part.

    So let's try to rely on CPOptimizer and enumeration now:

    using CP;

    range possibleValues=1..3;
    range dices=1..6;

    int occur[i in possibleValues]=i;
    dvar int dice[dices] in possibleValues;

    subject to
    {
    sum(i in dices) dice[i]==12;
    }

    int nbTimes=prod(i in dices) occur[dice[i]];

     main
    {
    cp.param.SearchType=24;
    cp.param.workers=1;

    var nbSol=0;
    thisOplModel.generate();
    cp.startNewSearch();
    while
    (cp.next()) {  thisOplModel.postProcess(); nbSol+=thisOplModel.nbTimes; }

    writeln("probability = ",nbSol," / ",Math.pow(6,6));
    }

    which gives the same:

     

    probability = 5284 / 46656

    regards and happy PI day

     

     

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer