Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; const int RANK = 0; const int SUIT = 1; const int NUM_SUITS = 4; const char STANDARD_SUITS[] = "dchs"; int usedSuits[] = {0, 0, 0, 0}; const char MOCK_SUITS[] = "ABCD"; const char BAD_SUIT = '*'; char pullSuit (int i) { if (usedSuits [i] &gt; 0) { return BAD_SUIT; } ++usedSuits [i]; return STANDARD_SUITS [i]; } void unpullSuit (int i) { --usedSuits [i]; } int indexOfSuit (char suit, const char suits[]) { int i; for (i = 0; i &lt; NUM_SUITS; ++i) { if (suit == suits [i]) { return i; } } return -1; } int legitimateSuits (const char suits[]) { return indexOfSuit (BAD_SUIT, suits) == -1; } int distinctSuits (const char suits[]) { int i, j; for (i = 0; i &lt; NUM_SUITS; ++i) { for (j = 0; j &lt; NUM_SUITS; ++j) { if (i != j &amp;&amp; suits [i] == suits [j]) { return 0; } } } return 1; } void printCards (char* mockCards[], int numMockCards, const char realizedSuits[]) { int i; for (i = 0; i &lt; numMockCards; ++i) { char* mockCard = mockCards [i]; char rank = mockCard [RANK]; char mockSuit = mockCard [SUIT]; int idx = indexOfSuit (mockSuit, MOCK_SUITS); char realizedSuit = realizedSuits [idx]; printf ("%c%c ", rank, realizedSuit); } printf ("\n"); } /* * Example usage: * char** mockCards = {"9A", "8A", "7B", "6B"}; * expand (mockCards, 4); */ void expand (char* mockCards[], int numMockCards) { int i, j, k, l; for (i = 0; i &lt; NUM_SUITS; ++i) { char a = pullSuit (i); for (j = 0; j &lt; NUM_SUITS; ++j) { char b = pullSuit (j); for (k = 0; k &lt; NUM_SUITS; ++k) { char c = pullSuit (k); for (l = 0; l &lt; NUM_SUITS; ++l) { char d = pullSuit (l); char realizedSuits[] = {a, b, c, d}; int legitimate = legitimateSuits (realizedSuits); if (legitimate) { int distinct = distinctSuits (realizedSuits); if (distinct) { printCards (mockCards, numMockCards, realizedSuits); } } unpullSuit (l); } unpullSuit (k); } unpullSuit (j); } unpullSuit (i); } } int main () { char* mockCards[] = {"9A", "8A", "7B", "6B"}; expand (mockCards, 4); return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload