Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Pure Function for String Selection

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60954] Re: Pure Function for String Selection
  • From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
  • Date: Wed, 5 Oct 2005 02:27:54 -0400 (EDT)
  • Organization: Uni Leipzig
  • References: <dht479$hl1$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

SelectStringQ[str_String] :=
Module[{ch = Characters[str]},
  ch = {First[#], Length[#]} & /@ Split[ch];
  Max[Last /@ Select[ch, MatchQ[#, {"X", _}] &]] < 
6 &&
  Max[Last /@ Select[ch, MatchQ[#, {"2", _}] &]] < 
6 &&
  Max[Last /@ Select[ch, MatchQ[#, {"1", _}] &]] < 
8
]

may help you.

Regards

  Jens

"Edson Ferreira" <edsferr at uol.com.br> schrieb im 
Newsbeitrag news:dht479$hl1$1 at smc.vnet.net...
| Dear members,
|
| I want to define a pure function to filter a set 
of strings.
|
| The strings that compose the set have all the 
same length and the only characters in these 
strings are "1", "X" and "2".
|
| The function that I want is like the one bellow:
|
| In[1]:=
| Unprotect[D];
| In[2]:=
| U={"2","X"};
| In[3]:=
| M={"1","2"};
| In[4]:=
| D={"1","X"};
| In[5]:=
| T={"1","2","X"};
| In[6]:=
| L=Flatten[Outer[StringJoin,T,T,T,D]];
| In[7]:=
| L = Select[L, Count[Characters[#], "1"] > 1 &];
|
| In this case, it counts the number of characters 
"1" in each string and select the ones that have 
more than one "1".
|
| I want a pure function, to be applied like the 
one in the example above, but for a different 
task.
|
| For each string, I want it to count the maximum 
number of repeated characters for each character.
|
| In other words, It must count the maximum number 
of repeated "1", "X" and "2" for each string.
|
| The string must be "selected" if:
|
| The longest run of repeated "1" is shorter than 
8 characters
| AND
| The longest run of repeated "X" is shorter than 
6 characters
| AND
| The longest run of repeated "2" is shorter than 
6 characters
|
| For example:
| "11112X122X1XXX" should be "selected"
| (there are four "1" in sequence, 3 "X" in 
sequence and 2 "2" in sequence)
|
| "122XXXXXX222XX"  should NOT be "selected"
| (there are six "X" in sequence)
|
| "11111111222112" should NOT be "selected"
| (there are 8 "1" in sequence)
|
| Thanks a lot !!!!!
|
| Edson Ferreira
|
| 



  • Prev by Date: Re: axes for Plot3D
  • Next by Date: Re: Pure Function for String Selection
  • Previous by thread: Re: Pure Function for String Selection
  • Next by thread: Re: Pure Function for String Selection