Re: Set construction with condition
- To: mathgroup at smc.vnet.net
- Subject: [mg61722] Re: Set construction with condition
- From: "Ray Koopman" <koopman at sfu.ca>
- Date: Thu, 27 Oct 2005 05:01:53 -0400 (EDT)
- References: <dj71qk$cmn$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
In[1]:= <<DiscreteMath`Combinatorica` In[2]:= StringJoin /@ Flatten[ Permutations /@ ( Flatten@MapThread[Table[#1,{#2}]&,{{"1","X","2"},#}]& /@ Select[Compositions[4,3],First@#<=2&] ), 1] Out[2]= {2222,X222,2X22,22X2,222X,XX22,X2X2,X22X,2XX2,2X2X,22XX,XXX2, XX2X,X2XX,2XXX,XXXX,1222,2122,2212,2221,1X22,12X2,122X,X122, X212,X221,21X2,212X,2X12,2X21,221X,22X1,1XX2,1X2X,12XX,X1X2, X12X,XX12,XX21,X21X,X2X1,21XX,2X1X,2XX1,1XXX,X1XX,XX1X,XXX1, 1122,1212,1221,2112,2121,2211,11X2,112X,1X12,1X21,121X,12X1, X112,X121,X211,211X,21X1,2X11,11XX,1X1X,1XX1,X11X,X1X1,XX11} In[3]:= Sort@% == Sort@Select[StringJoin/@Tuples[{"1","X","2"},4], StringCount[#,"1"]<=2&] Out[3]= True Edson Ferreira wrote: > Dear Mathematica experts, > > I have this definition of L which generates a list of 81 elements: > > L=Flatten[Outer[StringJoin,{"1","X","2"},{"1","X","2"},{"1","X","2"},{"1","X","2"}]] > > How can I modify this definition in order to generate only elements in which there are a maximum of 2 characters "1"? > > Thanks!!!!!!!!!!!!!! > > PS.: I don't want to filter the entire 81 elements set AFTER the generation. I want to generate it with the desired elements.