It struck me that someday I may be bilingual. Linds
-----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Roger Hui Sent: Sunday, September 28, 2014 9:11 AM To: Beta forum Subject: Re: [Jbeta] Concern about todayno I wrote a leap year function when I was a summer intern in APL (a loooong time ago). It amazed my more experienced colleagues because it used the inner product ≠.= leap←{0≠.=4 100 400∘.|⍵} leap (100×16+⍳6) ∘.+ ¯5+⍳11 0 1 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 The above translates directly into J: leap=: 0 ~:/ .= 4 100 400 |/ ] leap (100*16+i.6) +/ i:5 0 1 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 On Sat, Sep 27, 2014 at 9:43 PM, robert therriault <[email protected]> wrote: > Hi Leslie, > > I did say it was a heavy handed method to establish a leap year, so I > think we are in agreement. :-) > > The method that I ended up using was Raul's isLeap which is the J version > of your algorithm with a clever use of 2 | to ensure that divisible by 4, > not 100, 400 is the result > > isleap=. 2 | +/ 0= 4 100 400 | yt NB. yt is the year of the current date. > > By the way if you want to see todayno in J, all you need to do is type in > its name without an argument and it will return the definition > > todayno > 3 : 0 > 0 todayno y > : > a=. y > if. 1=x do. a=. 0 100 100 #: a end. > a=. ((*/r=. }: $a) , {:$a) $,a > if. 1<x do. > 'y m d h mm s'=. <"_1 |: a > else. > 'y m d'=. <"_1 |: a > end. > y=. 0 100 #: y - m <: 2 > n=. +/ |: <. 36524.25 365.25 *"1 y > n=. n + <. 0.41 + 0 30.6 #. (12 | m-3),"0 d > if. 1<x do. > n=. n + (24 60 60#.h,.mm,.s)%24*3600 > end. > 0 >. r $ n - 657378 > ) > > Also, I believe Linda was correct stating that it has day 0 as being > January 1st, 1800. This makes it more useful as a way of determining dates > relative to each other rather than a Gregorian-Julian conversion verb. > > todayno 1800 1 1 > 0 > > Cheers, bob > > On Sep 27, 2014, at 9:25 PM, 'Leslie S Satenstein' via Beta < > [email protected]> wrote: > > > leapyear = ((year mod 400) =0 ) or ((year mod 4 = 0) and not ((year mod > 100)= 0). > > > > It seems to me to be excessive use of todayno. Not having seen the code > to todayno, I would > > > > presume it uses a gregorian to Julian day number conversion, The > julian day is defined as > > > > (jan 1 year 1) = zero > > > > and todayno calculates the days since. > > > > I would presume that the correction includes the 10 day jump in year > 1580 where the Pope corrected the gregorian calendar by declaring the new > leapyear rule and .... October 21 1580 was deemed to be Nov 1st of that > year. > > > > Furthermore, if you want to know what day of the week the the 31th of > the month is, you would realize that it would be 3 days after February 28, > for non leap years and three days after Feb 29th on leapyears. A similar > rule applies for months with 30 days. > > This was an established convention. > > > > > > > > > > Regards > > > > > > Leslie > > > > > > > > > > > >> ________________________________ > >> From: robert therriault <[email protected]> > >> To: Beta forum <[email protected]> > >> Sent: Wednesday, September 24, 2014 10:28 AM > >> Subject: Re: [Jbeta] Concern about todayno > >> > >> > >> Hi Henry, > >> > >> ...and because it doesn't exist Feb 29, 2003 has the same todayno value > as March 1, 2003. That seems pretty reasonable to me since checking if > 2003 2 29 =&todayno 2003 3 1 becomes a way (albeit heavy handed) to > discern leap years. > >> > >> Cheers, bob > >> > >> On Sep 24, 2014, at 2:14 AM, Henry Rich <[email protected]> wrote: > >> > >>> 2003 2 29 doesn't exist > >>> > >>> Henry Rich > >>> > >>> On 9/24/2014 5:13 AM, Linda Alvord wrote: > >>>> Shouldn't the difference be 366 every four years. Bob's comments > caused me > >>>> to worry about leap year, and I am getting incorrect answers but they > may be > >>>> based on this. > >>>> > >>>> > >>>> > >>>> diff=: 13 :'(todayno x)-todayno y' > >>>> > >>>> > >>>> > >>>> (2005 3 1) diff 2004 2 29 > >>>> > >>>> 366 > >>>> > >>>> (2004 3 1) diff 2003 2 29 > >>>> > >>>> 366 > >>>> > >>>> (2003 3 1) diff 2002 2 29 > >>>> > >>>> 365 > >>>> > >>>> (2002 3 1) diff 2001 2 29 > >>>> > >>>> 365 > >>>> > >>>> (2001 3 1) diff 2000 2 29 > >>>> > >>>> 366 > >>>> > >>>> (2000 3 1) diff 1999 2 29 > >>>> > >>>> 366 > >>>> > >>>> (1999 3 1) diff 1998 2 29 > >>>> > >>>> 365 > >>>> > >>>> (1998 3 1) diff 1997 2 29 > >>>> > >>>> 365 > >>>> > >>>> (1997 3 1) diff 1996 2 29 > >>>> > >>>> 366 > >>>> > >>>> (1996 3 1) diff 1995 2 29 > >>>> > >>>> 366 > >>>> > >>>> > >>>> > >>>> > >>>> > >>>> > >>>> > >>>> ---------------------------------------------------------------------- > >>>> For information about J forums see > http://www.jsoftware.com/forums.htm > >> > >> > >> > >> > >>>> > >>> ---------------------------------------------------------------------- > >>> For information about J forums see http://www.jsoftware.com/forums.htm > >> > >> ---------------------------------------------------------------------- > >> For information about J forums see http://www.jsoftware.com/forums.htm > >> > >> > >> > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
