Re: Set of strings reducing problem
- To: mathgroup at smc.vnet.net
- Subject: [mg58595] Re: Set of strings reducing problem
- From: rolf at mertig.com
- Date: Sat, 9 Jul 2005 04:07:55 -0400 (EDT)
- References: <dal1ic$i7a$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
one possibility is to use simple pattern matching:
Mathematica 5.2 for Linux x86 (64 bit)
Copyright 1988-2005 Wolfram Research, Inc.
-- Motif graphics initialized --
In[1]:= !!ll
L={"11111111",
"11112111",
"1111X111",
"21122211"};
cl=Characters/@L;
r = Dispatch[{"1" + "X" -> "D", "1" + "2" -> "M", "1" + "U" -> "T",
"X" + "2" -> "U", "X" + "M" -> "T", "2" + "D" -> "T" }];
ncl =StringJoin @@@ ( cl //. {
x___List,
{a___, p_String, c___},
{a___, q_String, c___},
y___List } :>
{ x, {a, p+q/.r,c}, y } /;
StringQ[(p+q)/.r])
In[1]:= <<ll
Out[1]= {1111T111, 21122211}
--
Regards,
Rolf Mertig
GluonVision GmbH
Berlin