On 9/14/07, Dan Bron <[EMAIL PROTECTED]> wrote:
> No graphic representation is required. Can you tell me why your solution
> works?
Ok. In
hours=: (11|.1+i.12) {~ 12&% * i.
The left argument to {~ is a list of the hours on the face of the clock
The right argument to {~ are the indices into those hours corresponding
to the vertexes of the polygon.
i. generates a list of indices corresponding to the vertexes of the
polygon
12&% indicates how many hours are spanned by one of the sides
of the polygon, which is scaled by the result of i.
In other words:
(12&% * i.) 1
0
(12&% * i.) 2
0 6
(12&% * i.) 3
0 4 8
(12&% * i.) 4
0 3 6 9
(12&% * i.) 6
0 2 4 6 8 10
(12&% * i.) 12
0 1 2 3 4 5 6 7 8 9 10 11
Other cases generate errors
As an aside, here's an equivalent definition of hours:
hours=: 12&% 12&|&.<:@* i.
Here, instead of indexing, I compute the clock hour directly
from the clock index, using "clock arithmetic".
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm