[Date Index]
[Thread Index]
[Author Index]
Re: DeleteCases
*To*: mathgroup at smc.vnet.net
*Subject*: [mg98158] Re: [mg98144] DeleteCases
*From*: Bob Hanlon <hanlonr at cox.net>
*Date*: Wed, 1 Apr 2009 05:54:21 -0500 (EST)
*Reply-to*: hanlonr at cox.net
list = {{0, 0, 1, 1}, {0, 0, 2, 2}, {0, 0, 3, 3}, {1, 1, 0, 0}, {1, 1,
2, 2}, {1, 1, 3, 3}, {2, 2, 0, 0}, {2, 2, 1, 1}, {2, 2, 3,
3}, {3, 3, 0, 0}, {3, 3, 1, 1}, {3, 3, 2, 2}};
Union[list, SameTest -> (#1 == Reverse[#2] &)]
{{0, 0, 1, 1}, {0, 0, 2, 2},
{0, 0, 3, 3}, {1, 1, 2, 2},
{1, 1, 3, 3}, {2, 2, 3, 3}}
list //. {s___, {a_, a_, b_, b_}, m___, {b_, b_, a_, a_},
e___} :> {s, {a, a, b, b}, m, e}
{{0, 0, 1, 1}, {0, 0, 2, 2},
{0, 0, 3, 3}, {1, 1, 2, 2},
{1, 1, 3, 3}, {2, 2, 3, 3}}
n = 1; DeleteCases[list, _?(MemberQ[Take[list, n++], Reverse[#]] &)]
{{0, 0, 1, 1}, {0, 0, 2, 2},
{0, 0, 3, 3}, {1, 1, 2, 2},
{1, 1, 3, 3}, {2, 2, 3, 3}}
Bob Hanlon
---- Filippo Miatto <sottosupremo at gmail.com> wrote:
=============
Dear all,
Given this example list:
{{0, 0, 1, 1}, {0, 0, 2, 2}, {0, 0, 3, 3}, {1, 1, 0, 0}, {1, 1, 2, 2},
{1, 1, 3, 3}, {2, 2, 0, 0}, {2, 2, 1, 1}, {2, 2, 3, 3}, {3, 3, 0, 0},
{3, 3, 1, 1}, {3, 3, 2, 2}}
I need the elements {a,a,b,b} and {b,b,a,a} to be the same, i.e. i
want to delete one of the two occurrences from the list. (or all but
one if the condition is more complicated, say {a,b,c,d} and {b,a,c,d}
or {a,b,c,d} and {a,b,d,c})
How can i do that? Can i use DeleteCases? if so, what conditional
should I use to compare different elements in the list?
I tried without success for all the night.. (it's 6.15AM now!)
Thank you,
Filippo
Prev by Date:
**Re: Integrating package documentation with the documentation center**
Next by Date:
**Re: DeleteCases**
Previous by thread:
**Re: DeleteCases**
Next by thread:
**Re: DeleteCases**
| |