|
[Date Index]
[Thread Index]
[Author Index]
Re: multiple choice IF condition
- To: mathgroup at smc.vnet.net
- Subject: [mg56445] Re: [mg56427] multiple choice IF condition
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Tue, 26 Apr 2005 01:32:45 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
>-----Original Message-----
>From: marloo3 at mail15.com [mailto:marloo3 at mail15.com]
To: mathgroup at smc.vnet.net
>Sent: Monday, April 25, 2005 7:31 AM
>Subject: [mg56445] [mg56427] multiple choice IF condition
>
>could we have a more practical way than this way of choosing
>some numbers of the
>choice:
>
>a = 0;
>Table[If[i == 3 || i == 5 || i == 9 || i==18, a = a + i], {i, 20}]
>
>ie: i wish if it is possible like this:
>If[i==3 ||5 ||9||18, ...]
>
>Thanks very much
>mark
>
>
In[17]:= a = 0;
If[Thread[# == (3 || 5 || 9 || 18), Or], ++a, 0] & /@ Range[20]
Out[18]=
{0, 0, 1, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0}
In[19]:= Position[%, _?Positive]
Out[19]= {{3}, {5}, {9}, {18}}
--
Hartmut Wolf
Prev by Date:
can Mathematica be useful for this?
Next by Date:
Re: Problem with MatchQ and SameQ
Previous by thread:
Re: multiple choice IF condition
Next by thread:
Re: multiple choice IF condition
|