MathGroup Archive 2005

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

Search the Archive

Re: Set construction with condition

  • To: mathgroup at smc.vnet.net
  • Subject: [mg61516] Re: [mg61470] Set construction with condition
  • From: János <janos.lobb at yale.edu>
  • Date: Fri, 21 Oct 2005 00:38:01 -0400 (EDT)
  • References: <200510200307.XAA12764@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Oct 19, 2005, at 11:07 PM, 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.
>

Here is a newbie approach:

In[14]:=
Union[Flatten[Outer[
     StringJoin, {"1", "X",
      "2"}, {"1", "X", "2"},
     {"2", "X"}, {"X", "2"}]],
   Flatten[Outer[StringJoin,
     {"1", "X", "2"},
     {"X", "2"}, {"1", "X",
      "2"}, {"X", "2"}]],
   Flatten[Outer[StringJoin,
     {"1", "X", "2"},
     {"X", "2"}, {"X", "2"},
     {"1", "X", "2"}]],
   Flatten[Outer[StringJoin,
     {"X", "2"}, {"1", "X",
      "2"}, {"1", "X", "2"},
     {"X", "2"}]],
   Flatten[Outer[StringJoin,
     {"X", "2"}, {"1", "X",
      "2"}, {"X", "2"},
     {"1", "X", "2"}]],
   Flatten[Outer[StringJoin,
     {"X", "2"}, {"X", "2"},
     {"1", "X", "2"},
     {"1", "X", "2"}]]]
Out[14]=
{"1122", "112X", "11X2",
   "11XX", "1212", "121X",
   "1221", "1222", "122X",
   "12X1", "12X2", "12XX",
   "1X12", "1X1X", "1X21",
   "1X22", "1X2X", "1XX1",
   "1XX2", "1XXX", "2112",
   "211X", "2121", "2122",
   "212X", "21X1", "21X2",
   "21XX", "2211", "2212",
   "221X", "2221", "2222",
   "222X", "22X1", "22X2",
   "22XX", "2X11", "2X12",
   "2X1X", "2X21", "2X22",
   "2X2X", "2XX1", "2XX2",
   "2XXX", "X112", "X11X",
   "X121", "X122", "X12X",
   "X1X1", "X1X2", "X1XX",
   "X211", "X212", "X21X",
   "X221", "X222", "X22X",
   "X2X1", "X2X2", "X2XX",
   "XX11", "XX12", "XX1X",
   "XX21", "XX22", "XX2X",
   "XXX1", "XXX2", "XXXX"}

János


----------------------------------------------
Trying to argue with a politician is like lifting up the head of a  
corpse.
(S. Lem: His Master Voice)


  • Prev by Date: Re: regress versus fit -
  • Next by Date: Re: Double integral of a piecewise-constant function
  • Previous by thread: Set construction with condition
  • Next by thread: Re: Set construction with condition