Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It seems you want to create sequences of length 4 choosing 2 out of 4 letters, contained twice each ?</p> <p>My (quite rude) approach would be like this: It adds front to end, char by char to a sequence and narrows down possible solutions according to your rule in every step.</p> <p>This will create something like :</p> <pre><code>aabb, abba, baba, abab an so on </code></pre> <p>You can uncomment some lines to only allow for atomic pairs, this is done after the firs two letters, to add the second pair accordingly. (see comments in code)</p> <pre><code>aabb, abab, baba, bbaa .... </code></pre> <p>Here goes some code:</p> <pre><code>#include &lt;vector&gt; using namespace std, // ..... string letters = "abcd", tmpStr; string wrkString; // string to hold sequence during creation &lt;vector&gt;string sequences; // vector to hold all valid sequences for(int first=0;i&lt;letters.length();first++){ // every char as first char wrkString = letters.at(first); for(int second=0;i&lt;letters.length();second++){ // every char as second char wrkString += letters.at(second); // got first 2 now differentiate if(first == second) // having aa letters.erase(first,1); // if same twice, erase from possible elements else{ // having ab tmpStr = letters; // if different only this two remain possible solutions letters = tmpStr.at(first) + tmpStr.at(second); // uncomment here to add this pair again in same order (ab ab) // wrkString += wrkString; // sequences.push_back(wrkString); // letters = ''; } for(int third=0;i&lt;letters.length();third++){ // having aa or ab or ba or bb or ac ... wrkString += letters.at(third); if(wrkString.find(letters.at(third))==1) // having aac letters = letters.at(third); // if included it has to be added once more else // having acc letters -= letters.at(third); // if included twice, remove from possible elements for(int fourth=0;i&lt;letters.length();fourth++){ // here allways 1 letter left wrkString += letters.at(fourth); sequences.push_back(wrkString); // adding copy of sequence to vector } } } letters = "abcd"; // reset possible elements for next iteration } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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