I imagine you are talking about the definition of m11 at
http://www.jsoftware.com/help/phrases/date_time.htm
In other words: 0: ~:/ .= 4 100 400"_ |/ ]
For example:
(0: ~:/ .= 4 100 400"_ |/ ]) 1900 2000 2001 2002 2003 2004
0 1 0 0 0 1
1900 is not a leap hear, but 2000 is.
First off, I should perhaps note that this is old - nowadays we would
leave off the "_ from 4 100 400 because it is implied. But that's ok,
either way works:
(0: ~:/ .= 4 100 400 |/ ]) 1900 2000 2001 2002 2003 2004
0 1 0 0 0 1
Anyways, as I am sure you have already determined, the first step is
to find remainders:
(4 100 400"_ |/ ]) 1900 2000 2001 2002 2003 2004
0 0 1 2 3 0
0 0 1 2 3 4
300 0 1 2 3 4
Also, from a reference manual point of view, here's the definition of
"dot": http://www.jsoftware.com/help/dictionary/d300.htm
In other words ~:/ .= is like matrix inner product, with addition
being replaced by "not equals" (or "exclusive or") and with
multiplication being replaced by =
Or, put diferently, ~:/ .= is ~:/@(v"1 _)
In this case:
(0 (="1 _) 4 100 400"_ |/ ]) 1900 2000 2001 2002 2003 2004
1 1 0 0 0 1
1 1 0 0 0 0
0 1 0 0 0 0
(0 ~:/@(="1 _) 4 100 400"_ |/ ]) 1900 2000 2001 2002 2003 2004
0 1 0 0 0 1
In other words, if the year is divisible evenly by an odd number of
integers from the list 4 100 400 it's a leap year, but if it's
divisible evenly by an even number of those integers it's not a leap
year.
This corresponds to a nested if structure like this (pseudocode):
if (year evenly divisible by 4) then
if (year evenly divisible by 100) then
if (year evenly divisible by 400) then
leap year
else
not a leap year
else
leap year
else
not a leap year
(And, of course, modern cpu instruction piplelines struggle with
conditional statements, so there are some real advantages to avoiding
"if statements". See, for example:
http://software.intel.com/en-us/articles/branch-and-loop-reorganization-to-prevent-mispredicts
but, also, mathematical equivalences are a powerful tool of thought.)
Thanks,
--
Raul
On Thu, May 30, 2013 at 12:23 AM, <[email protected]> wrote:
> Can anyone show me how's the leap year verb work? I am confused on the use of
> dot. <br/><br/>m11=: 0: ~:/ .= 4 100 400"_ |/ ] NB. Is y a leap
> year?<br/>Why does it use ~:/ .= here? Is it the same as ~:/@:= ?
> <br/><br/><br/><br/>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm