MathGroup Archive 2005

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

Search the Archive

Re: make a set of conditions without the parameters

  • To: mathgroup at smc.vnet.net
  • Subject: [mg57953] Re: make a set of conditions without the parameters
  • From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
  • Date: Tue, 14 Jun 2005 05:10:18 -0400 (EDT)
  • Organization: Uni Leipzig
  • References: <d8jlkt$sum$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

t2 = {{0, 0, 0, {3}, 0, {4}, 0, 0, 0}, {0, {7}, 
{3}, 0, 0, 0, {1}, {4}, 0},
{{4},
0, 0, 0, {7}, 0, 0, 0, {6}}, {0, {9}, {5}, {4}, 0, 
{6}, 0, 0, 0}, {{8}, 0,
0, 0, {9}, 0, 0, 0, {3}}, {0, {4}, {6}, {8}, 0, 
{1}, 0, 0, 0}, {{6}, 0,
0, 0, 0, 0, 0, 0, {5}}, {0, {2}, {7}, 0, 0, 0, 
{3}, {8}, 0}, {0, 0,
0, {5}, 0, {7}, 0, 0, 0}};
rulesperline = Table[MapIndexed[ToString["#[["] <> 
ToString[#1] <>
ToString["]]!="] <> ToString[#2] &, (Part[#, i] & 
/@ Partition[Flatten[t2],
9] ) // Flatten], {i, 1, 9}];


newrules = ( Fold[(#1 /. ToString["#[[0]]!={"] <> 
ToString[#2] <>
  ToString["}"] -> X) &,
  rulesperline, Range[9]] ) /. X :> Sequence[]

(* I have changed the Unequal[] to UnsameQ[] 
because otherwise Select[]

will not get the desired True or False *)

newfunc = (((ToExpression[#, InputForm, Hold] & /@ 
newrules) //. {Hold[h1_],
               Hold[h2_], a___} :> {Hold[And[h1, 
h2]], a} ) /. {Hold[any_]} :>
               Function[any]) /. Unequal -> 
UnsameQ



Select[{{1, 2, 2, 3, 4, 5, 5, 7, 8, 9}, {2, 21, 
22, 23, 24, 25, 26, 27, 28,
29}}, newfunc[[1]]]


Regards

  Jens


"Guy Israeli" <guyi1 at netvision.net.il> schrieb im 
Newsbeitrag news:d8jlkt$sum$1 at smc.vnet.net...
> Hi,
>
> I have a big list made out of smaller lists. I 
> want to filter out specific
> smaller lists, for instance those who have 1 in 
> the first place and 3 in the
> 7th place.
>
> I know what item cannot be in what place for the 
> condition described above
> but the only thing i could do is to do those 
> rules using string like this:
>
>
> t2 = {{0, 0, 0, {3}, 0, {4}, 0, 0, 0}, {0, {7}, 
> {3}, 0, 0, 0, {1}, {4}, 0},
> {{4},
> 0, 0, 0, {7}, 0, 0, 0, {6}}, {0, {9}, {5}, {4}, 
> 0, {6}, 0, 0, 0}, {{8}, 0,
> 0, 0, {9}, 0, 0, 0, {3}}, {0, {4}, {6}, {8}, 0, 
> {1}, 0, 0, 0}, {{6}, 0,
> 0, 0, 0, 0, 0, 0, {5}}, {0, {2}, {7}, 0, 0, 0, 
> {3}, {8}, 0}, {0, 0,
> 0, {5}, 0, {7}, 0, 0, 0}};
> rulesperline = Table[MapIndexed[ToString["#[["] 
> <> ToString[#1] <>
> ToString["]]!="] <> ToString[#2] &, (Part[#, i] 
> & /@ Partition[Flatten[t2],
> 9] ) // Flatten], {i, 1, 9}];
>
> newrules = Fold[(#1 /. ToString["#[[0]]!={"] <> 
> ToString[#2] <>
> ToString["}"] -> X) &,
> rulesperline, Range[9]]
>
> which will result in
>
> {{X, X, #[[4]]!={3}, X, #[[8]]!={5}, X, 
> #[[6]]!={7}, X, X}, {X, #[[7]]!={2},
> X, #[[9]]!={4}, X, #[[4]]!={6}, X, #[[2]]!={8}, 
> X}, {X, #[[3]]!={2},
> X, #[[5]]!={4}, X, #[[6]]!={6}, X, #[[7]]!={8}, 
> X}, {#[[3]]!={1}, X,
> X, #[[4]]!={4}, X, #[[8]]!={6}, X, X, 
> #[[5]]!={9}}, {X, X, #[[7]]!={3},
> X, #[[9]]!={5}, X, X, X, X}, {#[[4]]!={1}, X, X, 
> #[[6]]!={4},
> X, #[[1]]!={6}, X, X, #[[7]]!={9}}, {X, 
> #[[1]]!={2}, X, X, X, X,
> X, #[[3]]!={8}, X}, {X, #[[4]]!={2}, X, X, X, X, 
> X, #[[8]]!={8}, X}, {X,
> X, #[[6]]!={3}, X, #[[3]]!={5}, X, #[[5]]!={7}, 
> X, X}}
>
> and then to cancel  the underlines
>
> newrulesfull = Select[#, # != "X" &] & /@ 
> newrules
>
> {{#[[4]]!={3}, #[[8]]!={5}, #[[6]]!={7}}, 
> {#[[7]]!={2}, #[[9]]!={4}, \
> #[[4]]!={6}, #[[2]]!={8}}, {#[[3]]!={2}, 
> #[[5]]!={4}, #[[6]]!={6}, \
> #[[7]]!={8}}, {#[[3]]!={1}, #[[4]]!={4}, 
> #[[8]]!={6}, #[[5]]!={9}}, \
> {#[[7]]!={3}, #[[9]]!={5}}, {#[[4]]!={1}, 
> #[[6]]!={4}, #[[1]]!={6}, \
> #[[7]]!={9}}, {#[[1]]!={2}, #[[3]]!={8}}, 
> {#[[4]]!={2}, #[[8]]!={8}}, \
> {#[[6]]!={3}, #[[3]]!={5}, #[[5]]!={7}}}
>
> The X here is just to mark that it is 
> unimportnat.
>
> however, each element is a string here. and now 
> starts my problem
>
> I would want to do Select[somelist, 
> And[newrulesfull [[1]]]&] meaning it
> will give the elements in somelist that match 
> the all of the conditions in
> rulesperline[[1]]. But since it is a string it 
> doesn't do much, and
> everytime I do ToExpression it gives me a lot of 
> errors because it doesn't
> know what #[[4]] or some other number is.
>
> How can I make a list of rules like that so that 
> I can use Select on those
> conditions?
>
>
>
> I'm sorry if my explanation was extremely 
> confusing, I will try to clearify
> it if parts were messy.
>
> Thank you very very very very very very much
>
>
>
> Guy.
>
> 



  • Prev by Date: Re: Peculiar behaviour of Mathematica code
  • Next by Date: For Loop and Array related
  • Previous by thread: make a set of conditions without the parameters
  • Next by thread: Re: make a set of conditions without the parameters