|
[Date Index]
[Thread Index]
[Author Index]
Re: Yet another simple question.
- To: mathgroup at smc.vnet.net
- Subject: [mg47190] Re: Yet another simple question.
- From: "Peter Pein" <no at spam.no>
- Date: Mon, 29 Mar 2004 04:22:36 -0500 (EST)
- References: <c438uh$emi$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
"George" <gtsavdar at auth.gr> schrieb im Newsbeitrag
news:c438uh$emi$1 at smc.vnet.net...
> As i'm new to this amazing world of Mathematica, i'm not able yet to
> do
> simple things that for an experienced user seem ridiculous.
>
> So i want to ask a simple question. If:
> +++++++++++++++++++++++++++++++++++++++++++++++
> y,m,day : integer positive variables
>
> yr,mr : integer positive variables which depend on y and m
>
> fff[day_] = Mod[day + 2*mr + Quotient[3*(mr + 1), 5] + yr + 2 +
> Quotient[yr, 4] + Quotient[yr, 400] - Quotient[yr, 100], 7];
> +++++++++++++++++++++++++++++++++++++++++++++++
>
> Now for a specific day=D i want to find the value of the integer
> variable Q which belongs to (D,D+7], so fff[Q]=1 would be true.
>
> So i write:
>
> Do[Q = Which[fff[x] == 1, x], {x, D + 1, D + 7, 1}]
>
> and i expect Q to take the appropriate value. But this doesn't work.
> Can anyone show me the way to the light?
>
> Thank you.
>
George,
11.: You shall not use function names for variables.
Do[q=Which...] assigns q seven times a value (Null or the actual value of
x). Your Do loop could be rewritten as q=If[fff[d+1]==1,x,Null].
You should stop evaluation of the loop, as soon as a solution has been
found:
q = Catch[Do[If[fff[x] == 1, Throw[x]], {x, d + 1, d + 7, 1}]]
or (slightly simpler):
q = Scan[If[fff[#1] == 1, Return[#1], $Failed] & , d + Range[7]].
If there is more than 1 possible solution,
d + Flatten[Position[fff /@ (d + Range[7]), 1]]
would give you a list of them.
These examples work iff values are assigned to yr, mr and d (_not_ D).
Peter
--
Peter Pein, Berlin
StringReplace["petsie at arcand.de",
Rule@@(ToLowerCase@ToString@Head@#&)/@{William&&S,2b||!2b}]
Prev by Date:
RE: Smooth animation
Next by Date:
Re: Yet another simple question.
Previous by thread:
Re: Yet another simple question.
Next by thread:
Re: Yet another simple question.
|