Pure Function for String Selection
- To: mathgroup at smc.vnet.net
- Subject: [mg60933] Pure Function for String Selection
- From: "Edson Ferreira" <edsferr at uol.com.br>
- Date: Tue, 4 Oct 2005 01:24:59 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
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