C# how to check n numbers of x (mod operator?) in a list
<p>I want to be able to control the sequence of entries in a list. The first five entries should read "A", the following two should read "B", then the next five "A", next two "B" and so on. I just can't quite get the logic right to be able to do this. </p>

<p>I seem to run into trouble where both "A" and "B" are divisible by their weight. In this code you can see this when you have 10 x A and 2 x B. My logic says the next should be an "A" when really, I want the next two to be "B" to give me a total of 10 x A, 4 x B at which point, it should be back to reporting A as the next in sequence. </p>

<p>My example code to get started is as follows, just add more "a" or more "b" to the data variable to test it;</p>

<pre><code>var aWeight = 5;
var bWeight = 2; 

var data = new string[] {"a", "a", "a", "a", "a"}; 

var aCount = data.Count(x =&gt; x == "a"); 
var bCount = data.Count(x =&gt; x == "b"); 

//aCount.Dump(); 
//bCount.Dump(); 

if(aCount % aWeight == 0) 
{
    if(aCount % aWeight == 0 &amp;&amp; bCount % bWeight == 0 &amp;&amp; bCount &gt; 0)
    {
        Console.WriteLine("Next is A! - pos 1"); 
        return;
    }

    Console.WriteLine("Next is B! - pos 2"); 
}
else if(bCount % bWeight == 0) 
{
    Console.WriteLine("Next is A! - pos 3" ); 
} 
</code></pre>