Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

Re: Yet another simple question.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg47187] Re: Yet another simple question.
  • From: gtsavdar at auth.gr (George)
  • Date: Mon, 29 Mar 2004 04:22:34 -0500 (EST)
  • References: <c438uh$emi$1@smc.vnet.net> <c45nmi$s3g$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

drbob at bigfoot.com (Bobby R. Treat) wrote in message news:<c45nmi$s3g$1 at smc.vnet.net>...
> The statement Q=Which[...] is executed at every step of the Do loop,
> so Q has the last value it was assigned. That's Null if fff[d+7] isn't
> 1, no matter what happened in earlier iterations.
> 
> If[fff[x]==1,Q=x] works much better, since it sets Q only when x has
> the right value. Which can be used instead of If, but it really should
> be reserved for applying more than one test.
> 
> The following stops the Do loop when you reach the x-value you want:
> 
> q = Catch[Do[fff[x] == 1 && Throw[x], {x, d + 1, d + 7}]]
> 
> However, there's no need for any loop at all. For fff[d] =
> 1,2,3,4,5,6,7 you need to add 7,6,5,4,3,2,1 to d, so q = d+8-fff[d]
> 
> D is a protected, built-in symbol for differentiation. It's
> recommended that you never start your own variables with capital
> letters; it avoids all those conflicts.
> 
> In addition, fff isn't a function of day alone as the pattern
> indicates; it also depends on mr and yr. It's usually best to reflect
> that in the pattern:
> 
> dayOfWeek[day_, month_, year_] = Mod[day + 2*month + Quotient[3*(
>     month + 1), 5] + year + 2 + Quotient[year, 4] +
>     Quotient[year, 400] - Quotient[year, 100], 7, 1];
> #+8-dayOfWeek[#,3,2004]&/@Range[31]
> 
> {7,7,7,7,7,7,14,14,14,14,14,14,14,21,21,21,21,21,21,21,28,28,28,28,28,28,28,\
> 35,35,35,35}
> 
> (The result for March 28-31, 2004 is March 35th, but presumably you're
> fixing that elsewhere.)
> 
> I added the final argument of Mod so that you wouldn't get 0 when you
> meant 1. Or maybe you do mean Sunday to be 0; I don't know. Your Do
> loop is looking for Sunday, isn't it?


Yes Sunday. 
Clever thing that you've made with q. I'm too uncomfortable with
Mathematica now to think such things. Thank you very much.


  • Prev by Date: Re: Yet another simple question.
  • Next by Date: RE: Building a list
  • Previous by thread: Re: Yet another simple question.
  • Next by thread: Dashed space curve