Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- bool isWantedCombination(int dices[5], int& repeatedNumber) {
- for (size_t i = 0; i < 5; i++)
- {
- int currentCounter = 1;
- for (size_t j = i + 1; j < 5; j++)
- {
- if (dices[i] == dices[j])
- {
- currentCounter++;
- }
- }
- if (currentCounter >= 3)
- {
- repeatedNumber = dices[i];
- return true;
- }
- }
- return false;
- }
- bool isReady(bool flags[6]) {
- for (size_t i = 0; i < 6; i++)
- {
- if (flags[i] == false)
- {
- return false;
- }
- }
- return true;
- }
- int getSuccesfulTry() {
- srand(time(NULL));
- int counter = 0;
- bool flags[6] = { false };
- while (!isReady(flags))
- {
- int dices[5];
- for (size_t i = 0; i < 5; i++)
- {
- dices[i] = (rand() % 6 + 1);
- }
- int repeatedNumber = 0;
- if (isWantedCombination(dices, repeatedNumber))
- {
- flags[repeatedNumber - 1] = true;
- }
- counter++;
- }
- return counter;
- }
- int main()
- {
- std::cout << getSuccesfulTry();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement