title: Number of arrangements with no consecutive letter the same
body: <p>This question is related to my question <a href="https://math.stackexchange.com/questions/2048646/number-of-arrangements-with-no-consecutive-letter-the-same-without-using-jair">here</a>. I am trying to get the following count programmatically to verify whether my mathematics is right.</p>
  
  <blockquote>
    <p>How many arrangements of the letters in the word PQRDDDEEEEFFFFF have
    no consecutive letter the same?</p>
  </blockquote>
  
  <p>How to determine this count using a php program?</p>
  
  <p><strong>My approach</strong></p>
  
  <ol>
  <li>generated all possible permutations using heap's algorithm and stored in an array <em>(used heap's algorithm as it is found faster)</em></li>
  <li>removed all duplicates using array_unique function</li>
  <li>Iterated through the array, identified the strings where adjacent letters are same using regexp /(.)\1/ and copied the strings where no adjacent letters are same to a new array.</li>
  <li>The new array has the list of elements which is required.</li>
  </ol>
  
  <p>My approach is working fine. But, for large strings (strings above 10 characters), memory issues are coming due to the large number of permutations and so the program does not work.</p>
  
  <p>Is there any alternative approach to determine this programmatically?</p>
  
  <p><strong>Note:</strong> </p>
  
  <p>I am looking for the count only and not the list of strings</p>