Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand you correctly, you have some sequence of numbers that can either be 1, 2, or 3, where the permutation of them doesn't matter (just the different combinations).</p> <p>That being the case:</p> <pre><code>std::vector&lt;int&gt; v{1, 2, 3}; std::sort(v.begin(), v.end()); </code></pre> <p>That will keep all of the different combinations properly aligned, and you could easily write a loop to test for equality.</p> <p>Alternatively, you could use a <code>std::array&lt;int, N&gt;</code> (where N is the number of possible values - in this case 3).</p> <pre><code>std::array&lt;int, 3&gt; a; </code></pre> <p>Where you would set <code>a[0]</code> equal to the number of <code>1</code>s you have, <code>a[1]</code> equal to the number of '2's, etc.</p> <pre><code>// if your string is 111 a[0] = 3; // if your string is 110 or 011 a[0] = 2; // if your string is 100 or 010 or 001 a[0] = 1; // if your string is 120 a[0] = 1; a[1] = 1; // if your string is 123 a[0] = 1; a[1] = 1; a[2] = 1; </code></pre> <p>If you are looking to store it in a single 32-bit integer:</p> <pre><code>unsigned long x = 1; // number of 1's in your string unsigned long y = 1; // number of 2's in your string unsigned long z = 1; // number of 3's in your string unsigned long result = x | y &lt;&lt; 8 | z &lt;&lt; 16; </code></pre> <p>To retrieve the number of each, you would do</p> <pre><code>unsigned long x = result &amp; 0x000000FF; unsigned long y = (result &gt;&gt; 8) &amp; 0x000000FF; unsigned long z = (result &gt;&gt; 16) &amp; 0x000000FF; </code></pre> <p>This is very similar to what happens in the <code>RBG</code> macros.</p>
    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. VO
      singulars
      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