NthWord - Maple Help

StringTools

 NthWord
 generate the nth word on a given alphabet

 Calling Sequence NthWord( alphabet, n )

Parameters

 alphabet - string; alphabet to use n - non-negative integer; nth word to generate

Description

 • The NthWord(alphabet, n) command generates the nth word on the given ordered alphabet, which consists of the characters in the string alphabet. The string alphabet must not contain repeated characters. Words are enumerated in shortlex order.
 • The $0$th word on any alphabet is the empty string $""$.
 • All of the StringTools package commands treat strings as (null-terminated) sequences of $8$-bit (ASCII) characters.  Thus, there is no support for multibyte character encodings, such as unicode encodings.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{seq}\left(\mathrm{NthWord}\left("abc",i\right),i=1..20\right)$
 ${"a"}{,}{"b"}{,}{"c"}{,}{"aa"}{,}{"ab"}{,}{"ac"}{,}{"ba"}{,}{"bb"}{,}{"bc"}{,}{"ca"}{,}{"cb"}{,}{"cc"}{,}{"aaa"}{,}{"aab"}{,}{"aac"}{,}{"aba"}{,}{"abb"}{,}{"abc"}{,}{"aca"}{,}{"acb"}$ (1)
 > $\mathrm{seq}\left(\mathrm{NthWord}\left("abcde",i\right),i=1..20\right)$
 ${"a"}{,}{"b"}{,}{"c"}{,}{"d"}{,}{"e"}{,}{"aa"}{,}{"ab"}{,}{"ac"}{,}{"ad"}{,}{"ae"}{,}{"ba"}{,}{"bb"}{,}{"bc"}{,}{"bd"}{,}{"be"}{,}{"ca"}{,}{"cb"}{,}{"cc"}{,}{"cd"}{,}{"ce"}$ (2)
 > $\mathrm{NthWord}\left("abc",{2}^{31}-1\right)$
 ${"abaababbbaacccacacca"}$ (3)
 > $\mathrm{NthWord}\left("abc",5\right)$
 ${"ab"}$ (4)
 > $\mathrm{NthWord}\left("bca",5\right)$
 ${"bc"}$ (5)