#include #include #include #include const unsigned maxCards = 20; const unsigned drawnCards = maxCards / 2; const unsigned allConfigs = 0x1 << maxCards; int drawSequence(unsigned config) { int numberOfSpells = 0; int bitPointer = 0; for (int i = 0; i < drawnCards; ++i, ++bitPointer) { if ((2 * __popcnt(config)) < (maxCards - bitPointer)) ++bitPointer; if (config & (0x1 << bitPointer)) ++numberOfSpells; config &= ~((0x2 << bitPointer) - 1u); } return numberOfSpells; } int main() { int spellsDrawn = 0; for (unsigned i = 0; i < allConfigs; ++i) { spellsDrawn += drawSequence(i); } int allCardsDrawn = allConfigs * drawnCards; std::cout << "spells drawn:" << spellsDrawn << std::endl; std::cout << "cards drawn:" << allCardsDrawn << std::endl; std::cout << "relation:" << double(spellsDrawn)/allCardsDrawn << std::endl; std::cin.ignore(); }