Re: Handling conditions on subvector elements

• To: mathgroup at smc.vnet.net
• Subject: [mg117583] Re: Handling conditions on subvector elements
• From: Bob Hanlon <hanlonr at cox.net>
• Date: Wed, 23 Mar 2011 02:55:53 -0500 (EST)

```Your conditions do not cover all cases. I assumed that you wanted 2 returned in the remaining cases.

v = {{1, 1, 2}, {1, 1, 3}, {2, 3, 1}, {1, 2, 3}, {3, 3, 1}};

If[(Equal @@ Most[#]) && Not[Equal @@ #], 1, 2] & /@ v

{1, 1, 2, 2, 1}

Bob Hanlon

---- Lengyel Tamas <lt648 at hszk.bme.hu> wrote:

=============
Dear Mathworld users,

I am struggling with a piece of code which should result in a List :

1) I have a vector with subvectors with triplets of values.
2) What I wish to achieve is a cycle that returns with a List with either
'1's or '2's in it.
3) The cycle should check whether the first and second element in
subvectors are equal and neither of them are equal with the third, if so,
return 1;
If all the elements are unequal, return 2

E.g.

V= {{1,1,2},{1,1,3},{2,3,1},{1,2,3},{3,3,1}} should return with {1, 1, 2,
2,1}

I'm assuming 'If' should be the key (as it returns 2 types of values), but
I can't seem to do it properly.

Tamas

--

Bob Hanlon

```

• Prev by Date: Re: Using Nearest on a group of points
• Next by Date: Re: Handling conditions on subvector elements
• Previous by thread: Handling conditions on subvector elements
• Next by thread: Re: Handling conditions on subvector elements