StringTools - Maple Programming Help

Home : Support : Online Help : Programming : Names and Strings : StringTools Package : Miscellaneous Utilities : StringTools/NthWord

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 $""$.

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)