That looks right.
Note that (((] | + + i.@]) #) { ]) can be replaced with (((] | [ + i.@]) #)
{ ]) or, even ((] | (+ i.)) #) { ]
Note also that behavior will be different from |. when x is not a scalar.
Thanks,
--
Raul
On Fri, May 30, 2014 at 6:42 PM, Dan Bron <[email protected]> wrote:
> 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).
>
> Now, if I had a list of all timestamps, the index change is simple: _1 |.
> list_of_timestamps . The problem is, I'm given timestamps as scalars
> (i.e. individual points in time), so I don't have a list. All I have is a
> timestamp and a maximum (which corresponds to the length of the list).
>
> Anyway, you can see the solution I cobbled together on the page, but what
> I'm interested in is a general way to express rotations arithmetically
> (i.e. as operations on indices). Is it true that after a rotation of R
> places, the indices i of a list of length L will be given by L | (L+R) + i
> ?
>
> Or, modelled in J:
>
> rotate =: ((] | + + i.@]) #) { ]
>
> _1 rotate i. 10
> 9 0 1 2 3 4 5 6 7 8
>
> _1 rotate 'hello world!'
> !hello world
>
> 2 rotate 'abcdefg'
> cdefgab
>
> (rotate"0 _~ i.@#) 'abcdefg'
> abcdefg
> bcdefga
> cdefgab
> defgabc
> efgabcd
> fgabcde
> gabcdef
>
> Can I rely on this identity for future work? Is there any scalar x and list
> y where x rotate y will differ from x |. y ?
>
> -Dan
>
> [1] Nautical Bell task on RosettaCode
> http://rosettacode.org/wiki/Nautical_bell#J
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm