Code:
Your letter-"table"
[ 0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11,
12, 13, 14, 15 ]
eligible next-letter positions for letter 10:
[ 0, 0, 0, 0,
0, 1, 1, 1,
0, 1, 0, 1,
0, 1, 1, 1 ]
now imagine, we had started with letter 7, then our unused-letter table would be this:
[ 1, 1, 1, 1,
1, 1, 1, 0,
1, 1, 0, 1,
1, 1, 1, 1 ]
a simple multiplication with the next-letter table would give us the currently available next letters:
[ 0, 0, 0, 0, [ 1, 1, 1, 1, [ 0, 0, 0, 0,
0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0,
0, 1, 0, 1, * 1, 1, 0, 1, = 0, 1, 0, 1,
0, 1, 1, 1 ] 1, 1, 1, 1 ] 0, 1, 1, 1 ]
From that on, it is just a simple trial-and-error procedure to work through all possible word combinations.