OFFSET
0,3
LINKS
Alois P. Heinz, Table of n, a(n) for n = 0..1000
Index entries for linear recurrences with constant coefficients, signature (0,0,7,0,0,2).
FORMULA
a(3n+2) = 2*a(3n+1).
From Alois P. Heinz, May 20 2013: (Start)
G.f.: (x-1)*(4*x^2+2*x+1) / (2*x^6+7*x^3-1).
a(n) = 7*a(n-3) + 2*a(n-6) for n>5. (End)
EXAMPLE
For n=6 the 23 words are: 112121, 112123, 112132, 112211, 112213, 112231, 112233, 112312, 112321, 112323, 121121, 121123, 121132, 121211, 121213, 121231, 121233, 121312, 121321, 121323, 123112, 123121 and 123123.
MAPLE
a:= n-> (<<0|1>, <2|7>>^iquo(n, 3, 'r').
[<<1, 3>>, <<1, 7>>, <<2, 14>>][r+1])[1, 1]:
seq(a(n), n=0..50); # Alois P. Heinz, May 20 2013
MATHEMATICA
LinearRecurrence[{0, 0, 7, 0, 0, 2}, {1, 1, 2, 3, 7, 14}, 40] (* Harvey P. Dale, Mar 06 2015 *)
PROG
(JavaScript)
function countOK(arr) {
var i, c=[0, 0, 0];
for (i=0; i<arr.length; i++) c[arr[i]-1]++;
if (c[0]>=c[1] && c[0]-c[1]<=2 && c[1]>=c[2] && c[1]-c[2]<=2) return true; else return false;
}
x=new Array();
x[0]=new Array();
x[0][0]=[1];
document.write(x[0].length+", ");
for (i=1; i<21; i++) {
x[i]=new Array();
xc=0;
for (j=0; j<x[i-1].length; j++) {
xn=x[i-1][j].concat([1]);
if (countOK(xn)) x[i][xc++]=xn;
xn=x[i-1][j].concat([2]);
if (countOK(xn)) x[i][xc++]=xn;
xn=x[i-1][j].concat([3]);
if (countOK(xn)) x[i][xc++]=xn;
}
document.write(x[i].length+", ");
}
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Jon Perry, May 19 2013
STATUS
approved