******************************* *** The hack uses generator *** ******************************* ** Command line arguments ** no arguments ** Generated test ** Enter p (probability of picking the missing face when one is known). For equal faces enter 0.5: ** Generator source ** #include using namespace std; // Analytical calculation for 2 faces: // If p is probability to pick the missing face when one face is already found: // Expected turns = 1 + 1/p double expected_formula(double p) { if (p <= 0.0) return INFINITY; return 1.0 + 1.0 / p; } // Optional Monte-Carlo simulation to verify the result double simulate(double p, long long trials = 2000000) { std::mt19937_64 rng(123456789); std::bernoulli_distribution pickA(1.0 - p); // probability of picking face A long long totalTurns = 0; for (long long t = 0; t < trials; ++t) { bool haveA = false, haveB = false; long long turns = 0; while (!(haveA && haveB)) { ++turns; bool chooseA = pickA(rng); if (chooseA) haveA = true; else haveB = true; } totalTurns += turns; } return double(totalTurns) / double(trials); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); double p; // probability to pick the missing face when one is already collected // For the symmetric case (two faces equally likely), p = 0.5 cout << "Enter p (probability of picking the missing face when one is known). " << "For equal faces enter 0.5: "; if (!(cin >> p)) return 0; cout << fixed << setprecision(10); double E = expected_formula(p); cout << "Analytical expected turns = " << E << "\n"; // optional: run a quick simulation to verify (comment out if you don't want it) cout << "Run simulation to verify? (y/n): "; char c; cin >> c; if (c == 'y' || c == 'Y') { double sim = simulate(p, 500000); // half-million trials by default cout << "Simulated average turns = " << sim << " (trials = 500000)\n"; } return 0; }