title: How many ways to make number length of n from 0, 1 and 2?
body: <p>You have a number length n, consisting of 3 numbers: 0,1 and 2:<br>
  021112201...  </p>
  
  <p>a) how many ways to make this number if two zeros can t stay together?<br>
  b) how many ways to make this number if two zeros and two ones can t stay together?   </p>
  
  <p>I wrote code for solving this below. Is there a way to calculate this task manually with simple formula?</p>
  
  <pre><code>#include &lt;stdio.h&gt;  
  
  int main() {   
      int n; //length 
      scanf("%d", &amp;n);
      int a[n+1][3];
      a[1][0]=a[1][1]=a[1][2];
      for (int i=2; i&lt;=n; ++i) {
          // only for zeroes
          a[i][0] = a[i-1][0]+a[i-1][1]+a[i-1][2];
          a[i][1] = a[i-1][0]+a[i-1][2];
          a[i][2] = a[i-1][0]+a[i-1][1]+a[i-1][2];
          // for zeroes and ones
          /*
          a[i][0] = a[i-1][0]+a[i-1][1]+a[i-1][2];
          a[i][1] = a[i-1][0]+a[i-1][2];
          a[i][2] = a[i-1][0]+a[i-1][1];
          */
       }
       printf("sum: %d;", a[n][0] + a[n][1] +  a[n][2];
       return 0;
  </code></pre>