Let's call a non-empty list of strings a mesa if the following conditions hold:
- Each listed string is non-empty and uses only characters that occur in the first string.
- Each successive string is exactly one character longer than the preceding string.
- No string in the list is a subsequence of any other string in the list.
The term "mesa" is from visualizing like this (where the x
s are to be various characters):
xx..x
xx..xx
xx..xxx
.
.
.
xx..xxx..x
NB: It's a mathematical fact that only finitely many mesas begin with a given string. Note the distinction between subsequence vs. substring; e.g., 'anna' is a subsequence (but not a substring) of 'banana'.
Challenge:
- Write the shortest program that takes an arbitrary non-empty alphanumeric input string and outputs the number of mesas that begin with that string.
Input (stdin):
- Any non-empty alphanumeric string.
Output (stdout):
- The number of mesas that begin with the input string.
Scoring:
- The winner is the program with the least number of bytes.
Example mesas
Only one mesa starts with a
:
a
Only one mesa starts with aa
:
aa
Many mesas start with ab
:
ab ab ab ab (and so on)
baa aaa bbb
bbba bbaa
baaaa
aaaaaa
ab
,bbb
as a mesa just by stopping at the second term. Is that valid? Or do they always have to be made as long as possible? Also, if there are multiple possible rearrangements of thenth
term (such asbaa
,aba
,aab
), do they all count as separate mesas as well (providing of course they all follow the rules)? \$\endgroup\$ – mellamokb Apr 23 '12 at 14:12ab
,ab/baa
,ab/bbb
,ab/bbb/bbaa
,ab/bbb/bbaa/baaaa
,ab/bbb/bbaa/baaaa/aaaaaa
are different mesas. \$\endgroup\$ – r.e.s. Apr 23 '12 at 14:55