fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. struct OddsEntry
  8. {
  9. int multiplier;
  10. int threshold;
  11. };
  12.  
  13. OddsEntry RollThresholds[] =
  14. {
  15. { 4, 5 },
  16. { 8, 6 },
  17. { 16, 7 },
  18. { 32, 8 },
  19. { 64, 9 }
  20. };
  21.  
  22. int RollD10()
  23. {
  24. float random = (float(rand()) / RAND_MAX) * 10.f;
  25. return(int(random));
  26. }
  27.  
  28. int main() {
  29. srand(time(0));
  30. static constexpr int Iterations = 5000000;
  31. for(const OddsEntry& entry : RollThresholds)
  32. {
  33. cout << "For multiplier " << entry.multiplier << "X, little one wins ";
  34. int wins = 0;
  35. for(int iteration = 0; iteration < Iterations; ++iteration)
  36. {
  37. int littleScore = 0;
  38. int bigScore = 0;
  39. while((littleScore < 6) && (bigScore < 6))
  40. {
  41. const int roll = RollD10();
  42. const int increment = (RollD10() < 6) ? 1 : 2;
  43. if(roll < entry.threshold)
  44. {
  45. bigScore += increment;
  46. }
  47. else
  48. {
  49. littleScore += increment;
  50. }
  51. }
  52. if(littleScore >= 6)
  53. {
  54. wins++;
  55. }
  56. }
  57. cout << (float(wins) / Iterations) * 100.f << "%\n";
  58. }
  59. return 0;
  60. }
Success #stdin #stdout 4s 4460KB
stdin
Standard input is empty
stdout
For multiplier 4X, little one wins 49.9582%
For multiplier 8X, little one wins 29.0432%
For multiplier 16X, little one wins 12.7799%
For multiplier 32X, little one wins 3.5343%
For multiplier 64X, little one wins 0.34936%