MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

String substitution system

  • To: mathgroup at smc.vnet.net
  • Subject: [mg97176] String substitution system
  • From: Hauke Reddmann <fc3a501 at uni-hamburg.de>
  • Date: Sat, 7 Mar 2009 02:38:57 -0500 (EST)

Another question that is probably too trivial for you :-)

I want to generate all words A,B,C,D,AA,AB,...,DD,AAA,...
until, eh, 6-7 letters should suffice, and put them in a list.
The following string replacements are legal:
CC->C
DD->D
CA->C
AC->C
DB->D
BD->D
CDC->C
DCD->D
CBC->C
DAD->D
ABC->DC
CBA->CD
BAD->CD
DAB->DC
BAB->ABA
Note that everything but the last one shortens the word
and thus strings containing these substrings may be simply
dropped if you generate the words ordered by length, but the last
one is a bit tricky - BABBC=ABABC=AABAC=AABC and
ABAAD=BABAD=BBABD=BBAD so you may have to use it both
ways and repeatedly.
Now I'm an old FORTRAN chap and being nearly 50 years old,
I probably won't learn the Kamasutra of recursive function
calls anymore :-) But surely you'll have a three-liner
for this problem?
P.S. Actually the strings are cyclic too - CBBA=ACBB=CBB.
P.P.S. Remember, poor University, version 5.2 ;-)
-- 
Hauke Reddmann <:-EX8    fc3a501 at uni-hamburg.de
Nur Schufte schuften - Genie genießt.


  • Prev by Date: Forgets Variables?
  • Next by Date: Re: typsetting bug still present in Mathematica 7.01
  • Previous by thread: Re: Forgets Variables?
  • Next by thread: Re: String substitution system