I want a function myfun
that generates list like this
myfun[1]
{{1}}
myfun[2]
{{0, 1}, {1, 0}, {1, 1}, {1, 2}}
myfun[3]
{{0, 0, 1}, {0, 1, 0}, {0, 1, 1}, {0, 1, 2}, {1, 0, 0}, {1, 0, 1}, {1, 0, 2}, {1, 1, 0}, {1, 1, 1}, {1, 1, 2}, {1, 2, 0}}
myfun[4]
{{0, 0, 0, 1}, {0, 0, 1, 0}, {0, 0, 1, 1}, {0, 0, 1, 2}, {0, 1, 0, 0}, {0, 1, 0, 1}, {0, 1, 0, 2}, {0, 1, 1, 0}, {0, 1, 1, 1}, {0, 1, 1, 2}, {0, 1, 2, 0}, {1, 0, 0, 0}, {1, 0, 0, 1}, {1, 0, 0, 2}, {1, 0, 1, 0}, {1, 0, 1, 1}, {1, 0, 1, 2}, {1, 0, 2, 0}, {1, 1, 0, 0}, {1, 1, 0, 1}, {1, 1, 0, 2}, {1, 1, 1, 0}, {1, 1, 1, 1}, {1, 1, 1, 2}, {1, 1, 2, 0}, {1, 2, 0, 0}}
myfun[5]
{{0, 0, 0, 0, 1}, {0, 0, 0, 1, 0}, {0, 0, 0, 1, 1}, {0, 0, 0, 1, 2}, {0, 0, 1, 0, 0}, {0, 0, 1, 0, 1}, {0, 0, 1, 0, 2}, {0, 0, 1, 1, 0}, {0, 0, 1, 1, 1}, {0, 0, 1, 1, 2}, {0, 0, 1, 2, 0}, {0, 1, 0, 0, 0}, {0, 1, 0, 0, 1}, {0, 1, 0, 0, 2}, {0, 1, 0, 1, 0}, {0, 1, 0, 1, 1}, {0, 1, 0, 1, 2}, {0, 1, 0, 2, 0}, {0, 1, 1, 0, 0}, {0, 1, 1, 0, 1}, {0, 1, 1, 0, 2}, {0, 1, 1, 1, 0}, {0, 1, 1, 1, 1}, {0, 1, 1, 1, 2}, {0, 1, 1, 2, 0}, {0, 1, 2, 0, 0}, {1, 0, 0, 0, 0}, {1, 0, 0, 0, 1}, {1, 0, 0, 0, 2}, {1, 0, 0, 1, 0}, {1, 0, 0, 1, 1}, {1, 0, 0, 1, 2}, {1, 0, 0, 2, 0}, {1, 0, 1, 0, 0}, {1, 0, 1, 0, 1}, {1, 0, 1, 0, 2}, {1, 0, 1, 1, 0}, {1, 0, 1, 1, 1}, {1, 0, 1, 1, 2}, {1, 0, 1, 2, 0}, {1, 0, 2, 0, 0}, {1, 1, 0, 0, 0}, {1, 1, 0, 0, 1}, {1, 1, 0, 0, 2}, {1, 1, 0, 1, 0}, {1, 1, 0, 1, 1}, {1, 1, 0, 1, 2}, {1, 1, 0, 2, 0}, {1, 1, 1, 0, 0}, {1, 1, 1, 0, 1}, {1, 1, 1, 0, 2}, {1, 1, 1, 1, 0}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 2}, {1, 1, 1, 2, 0}, {1, 1, 2, 0, 0}, {1, 2, 0, 0, 0}}
Feature of the list:
Each element is of length K
.
Only 0,1,2 are allowed.
Must have at least a 1.
Can have 0s,1s only, without a 2.
If 2 exists, must be after at least a 1 AND after any 2, there must be 0 (or 0s or nothing).
The length of the list is determined by
nLength[K_Integer] := LinearRecurrence[{4, -5, 2}, {1, 4, 11}, K][[K]];
So the length of the first 8 lists are {1,4,11,26,57,120,247,502} and so on.
Some pieces I have got:
mytest[K_] := Drop[Flatten[{Tuples[{0, 1}, K], ReplaceList[ConstantArray[0, K], {a___, x_, b___, y_, c___} :> {a, 1, b, 2, c}]}, 1], 1];
It only works for the first two lists. And there are pieces missing (obviously). How can I create this effectively for large K
, like 20,30? We will get length of list equal to 2097130 and 2147483616.
K
consisting of the numbers 0, 1, and 2, such that only zeros can follow a 2, and each list must contain at least one 1; is this correct? $\endgroup$