Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think it is best to handle this with math.</p> <pre><code>$range = array('a','b','c'); $length = 3; // looking for 3 digit results $minRep = 2; // with &gt;=2 consecutive characters $rangeLength = count($range); $count = (pow($rangeLength,$length-$minRep+1) * ($length-$minRep+1)) - ($rangeLength * ($length-$minRep)); // is the result </code></pre> <p>Now, $count is getting true result for three situation. But it may not be general formula and need to improve.</p> <p>Try to explain it:</p> <pre><code>pow($rangeLength,$length-$minRep+1) </code></pre> <p>in this, we count repetitive characters like as one. For instance, in second example that you gave, we think in aab, aa is a one character. Because, two characters need to change together. We think now there is two character like xy. So there is same possibilities for both character a, b, and c namely 3 ($rangeLength) possible value for two characters($length-$minRep+1). So 3^2=9 is possible situations for second example.</p> <p>We calculate 9 is for just xy not yx. For this, we multiply length of xy ($length-$minRep+1). And then we have 18.</p> <p>It can be seemed that we calculated the result, but there is a repeat in our calculation. We didn't reckon with this situation: xy => aaa and yx => aaa. For this, we calculate and substract repeated results</p> <pre><code>- ($rangeLength * ($length-$minRep)) </code></pre> <p>So after this, we get result. As i said begining of the description, this formula may need to improve.</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.
 

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