That's a neat way of looking at it. We could even express this with under:

 rotate =: {. ,&.:|. }.

And since , (join) is the obverse of split (break head from tail), we could 
even express this in English the other way around: reverse under split.

With that said, this approach (however expressed) doesn't answer for the 
Nautical Bell task. There, we don't have a list, so structural operations, like 
split and reverse, don't make sense. We need a value-oriented operation. 
Specially, we need an verb of 3 (independent, atomic) parameters: list-length, 
rotation-amount, index. 

For the sake of argument, if we fix the degree of rotation, then to satisfy the 
requirement, you must supply a scalar dyadic verb, which given a list's length 
and one of its indices (ie an integer between 0 and length-1, inclusive), 
produces a new index (in the same domain) which represents a rotation of the 
given degree .

Since your verb is scalar, by definition, it is blind to structure, and must 
deal with values. In particular, it deals with transformations of integers. 
Given the nature of the task, those transformations are likely to be 
fundamental mathematical operations. In other words, your verb will use 
arithmetic to create rotations. Hence the subject line of this thread.

-Dan

> On May 31, 2014, at 12:09 AM, David Lambert <[email protected]> wrote:
> 
> Rotations are anagrams, and _1&A. is reverse.  An equivalent rotation 
> algorithm is "reverse the first and last parts of the list, then reverse the 
> entire list".
> 
> NB. rotation using reversal
> 
> rotate =: [: |. |.@{. , |.@}.
> 
> 3 (|. -: rotate) 'abcdefg'
> 1
> 
>>  3. Arithmetic of rotations (Dan Bron)
>> Date: Fri, 30 May 2014 18:42:06 -0400
>> From: Dan Bron <[email protected]>
>> To: [email protected]
>> Subject: [Jprogramming] Arithmetic of rotations
>> Message-ID: <PC1993201405301842060057c8ca11bf@thinkpad-2013>
>> Content-Type: text/plain; charset=iso-8859-1
>> 
>> While trying to implement the Nautical Bell task on RosettaCode [1], I
>> needed an arithmetic way to express a rotation. The short story is clocks
>> on ships are origin-1, whereas modern clocks are origin zero (midnight is
>> 00:00:00.000).
> 
> ----------------------------------------------------------------------
> 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