#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
struct OddsEntry
{
int multiplier;
int threshold;
} ;
OddsEntry RollThresholds[ ] =
{
{ 4 , 5 } ,
{ 8 , 6 } ,
{ 16 , 7 } ,
{ 32 , 8 } ,
{ 64 , 9 }
} ;
int RollD10( )
{
float random = ( float ( rand ( ) ) / RAND_MAX ) * 10 .f ;
return ( int ( random) ) ;
}
int main( ) {
srand ( time ( 0 ) ) ;
static constexpr int Iterations = 5000000 ;
for ( const OddsEntry& entry : RollThresholds)
{
cout << "For multiplier " << entry.multiplier << "X, little one wins " ;
int wins = 0 ;
for ( int iteration = 0 ; iteration < Iterations; ++ iteration)
{
int littleScore = 0 ;
int bigScore = 0 ;
while ( ( littleScore < 6 ) && ( bigScore < 6 ) )
{
const int roll = RollD10( ) ;
const int increment = ( RollD10( ) < 6 ) ? 1 : 2 ;
if ( roll < entry.threshold )
{
bigScore + = increment;
}
else
{
littleScore + = increment;
}
}
if ( littleScore >= 6 )
{
wins++ ;
}
}
cout << ( float ( wins) / Iterations) * 100 .f << "%\n " ;
}
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGxpYj4KI2luY2x1ZGUgPGN0aW1lPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnN0cnVjdCBPZGRzRW50cnkKewoJaW50IG11bHRpcGxpZXI7CglpbnQgdGhyZXNob2xkOwp9OwoKT2Rkc0VudHJ5IFJvbGxUaHJlc2hvbGRzW10gPQp7Cgl7IDQsIDUgfSwKCXsgOCwgNiB9LAoJeyAxNiwgNyB9LAoJeyAzMiwgOCB9LAoJeyA2NCwgOSB9Cn07CgppbnQgUm9sbEQxMCgpCnsKCWZsb2F0IHJhbmRvbSA9IChmbG9hdChyYW5kKCkpIC8gUkFORF9NQVgpICogMTAuZjsKCXJldHVybihpbnQocmFuZG9tKSk7Cn0KCmludCBtYWluKCkgewoJc3JhbmQodGltZSgwKSk7CglzdGF0aWMgY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