I think the code you are looking for is

   bgn=. todayno (2004+i.3) ,/@:(,"0 1/) (1+i.12),.1
.

Also, for the second option, I would recommend

   _3 ]\ , > ,/&.>/ 2004 1 1 (+ i.)&.> 3 12 30

Or, for a more cheat-looking option,

   2004 1 1 +"1 (#: i.@(*./)) 3 12 31

None of this is tested; I can explain or edit it on request.

Marshall

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of PackRat
Sent: Sunday, November 28, 2010 9:50 PM
To: Programming forum
Subject: [Jprogramming] Calendrical "odometer"--how to?

[1] The "London Gold Fix" plot demo I mentioned previously has the
line:

   bgn=. todayno 2004,.(1+i.12),.1

I'd like to change the  2004  to something like  (2004+i.3) so that a plot
could handle multiple years rather than just one.  Although that's the
intuitive approach a beginner like me would take, it doesn't work that way.
(The problem, of course, is that "stitch" can take a list and an atom, but
it can't take two lists where each value of the one list is repeated as a
fill for each value of the other list.)  How can I adjust that line to get
an output like this:

2004  1  1
2004  2  1
2004  3  1
. . .
2004 12  1
2005  1  1
2005  2  1
2005  3  1
. . .
2005 12  1
2006  1  1
2006  2  1
2006  3  1
. . .
2006 12  1

[2] Additionally, just as a matter of interest, how would one write a more
complete "calendrical odometer"?  In other words, all three elements (year,
month, day) cycle through their values.  (Leap years present problems,
though.)  The result would look like:

2004  1  1
2004  1  2
. . .
2004  1 31
2004  2  1
2004  2  2
. . .
2004 12 31
2005  1  1
2005  1  2
. . .
2006 12 31

(I suppose one could "cheat" by doing the calculation backwards--that is,
going from a sequence of day numbers to the equivalent yyyy mm dd
values.)

[3] More challenging (I presume), how would one create such an odometer
using any starting and ending dates in the format yyyy mm dd?  I presume
this might possibly be a multiline explicit verb (no tacit, please).
(Again, I suppose one could "cheat", as above.)

I really do appreciate the help you all give--thanks!

Harvey

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to