MathGroup Archive 2005

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

Search the Archive

Re: Set construction with condition

  • To: mathgroup at
  • Subject: [mg61722] Re: Set construction with condition
  • From: "Ray Koopman" <koopman at>
  • Date: Thu, 27 Oct 2005 05:01:53 -0400 (EDT)
  • References: <dj71qk$cmn$>
  • Sender: owner-wri-mathgroup at

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,

In[3]:= Sort@% == Sort@Select[StringJoin/@Tuples[{"1","X","2"},4],
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.

  • Prev by Date: tensor product
  • Next by Date: Re: ParametricPlot3D
  • Previous by thread: Re: Set construction with condition
  • Next by thread: regress versus fit - force through zero/force constant term to zero