clever stuff thanks,
here is an adverb form for the clock precision function. m is the number of
points on the clock up to 90 degrees. The input is structured that way so that
the requirement that it be a multiple of 4 is removed.
points =: 1 : '((4*m)|[+{:@]) ,~ (2&{.)@] + (3 : ''|:(,:y|.])(,-)}:y-|i: y'' m)
{~ (4*m)|[+{:@]'
creates a tacit verb:
1 points
(4 | [ + {:@]) ,~ 2&{.@] + (4 2$0 1 1 0 0 _1 _1 0) {~ 4 | [ + {:@]
d =: 4 : 'plot ;/ |: 2{."1 x points/\. 0,~ |. ($~x*#) y'
is there a name for this shape?
90 d 1
3 d 2 9
2 d 1 6
trippy:
90 d 1 180
----- Original Message -----
From: Raul Miller <[email protected]>
To: Programming forum <[email protected]>
Cc:
Sent: Saturday, April 18, 2015 9:43 AM
Subject: Re: [Jprogramming] an interesting plot toy
It seems to me that you are doing a fair bit of extra work here, with
your 'boxscan'.
That said, first I'd like to point out that it should really have been
named 'boxreduce' or 'boxfold'. A scan would have used /\ (or /\.)
instead of just /
And, indeed, when I look at how you are using it:
(],[move12{:@])
... you are building up a result which would have been rather like /\.
in nature.
And sometimes this style of computation can be an important thing. But
it's not really necessary for this problem.
When I look at the arguments being passed, your initial values is 0 0
0 and everything else that you put in a box is a scalar. So basically,
all you have to do is replace }:@:] in your definition of move12 with
(2&{.)@]
Once you've done that, you can use 0 for your initial state and you
can eliminate all the boxing and unboxing.
Something like this, perhaps:
move12 =: (12|[+{:@]) ,~ (2&{.)@] + ((,.~_4|.|.)(i:_3),i:2) {~ 12|[+{:@]
require 'plot'
draw =: 3 : 'plot ;/ |: 2{."1 move12/\. 0,~ |. ($~12*#) y'
The plotted sequence here is reversed from the order of your original
version, but that is not a visible change. (You need /\. instead of /\
because you want to maintain the same initial state for each item of
the result. Also, I believe that /\. is O(n) while /\ is O(n^2) in the
general case and only O(n) where special code exists.)
Or, as you had initially suggested, replace that 12*# with 144*#
(That said, note also that what I have proposed here is an
optimization - and one should never concern oneself with optimizations
until after they have the code working properly.
Thanks,
--
Raul
On Fri, Apr 17, 2015 at 3:09 PM, 'Pascal Jasmin' via Programming
<[email protected]> wrote:
> can visualize this as a logo robot that moves 3 spaces at a time in the
> direction of a clockface. It moves like a chess knight for directions that
> are not 12 3 6 9.
>
> boxscan =: ((&.>)/)(>@:)
> move12 =: (12 | [ + {:@]) ,~ }:@:] + (12 2$0 3 1 2 2 1 3 0 2 _1 1 _2 0 _3 _1
> _2 _2 _1 _3 0 _2 1 _1 2) {~ 12 | [ + {:@]
>
> require 'plot'
>
> draw =: 3 : 'plot ;/ |: 2{."1 (],[move12{:@])boxscan (< ,: 0 0 0),~ |. ;/
> ($~12*#) y'
>
> for non repeating patterns, can change the 12*# to 144*#
>
> the easiest patterns to understand
> draw 1
> draw 3
>
> some cool patterns
>
>
> draw 1 4
> draw 3 2 6 1 4 11
> draw 1 3 4 3 11
> draw 1 5 10 4 2
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----- Original Message -----
From: Raul Miller <[email protected]>
To: Programming forum <[email protected]>
Cc:
Sent: Saturday, April 18, 2015 9:43 AM
Subject: Re: [Jprogramming] an interesting plot toy
It seems to me that you are doing a fair bit of extra work here, with
your 'boxscan'.
That said, first I'd like to point out that it should really have been
named 'boxreduce' or 'boxfold'. A scan would have used /\ (or /\.)
instead of just /
And, indeed, when I look at how you are using it:
(],[move12{:@])
... you are building up a result which would have been rather like /\.
in nature.
And sometimes this style of computation can be an important thing. But
it's not really necessary for this problem.
When I look at the arguments being passed, your initial values is 0 0
0 and everything else that you put in a box is a scalar. So basically,
all you have to do is replace }:@:] in your definition of move12 with
(2&{.)@]
Once you've done that, you can use 0 for your initial state and you
can eliminate all the boxing and unboxing.
Something like this, perhaps:
move12 =: (12|[+{:@]) ,~ (2&{.)@] + ((,.~_4|.|.)(i:_3),i:2) {~ 12|[+{:@]
require 'plot'
draw =: 3 : 'plot ;/ |: 2{."1 move12/\. 0,~ |. ($~12*#) y'
The plotted sequence here is reversed from the order of your original
version, but that is not a visible change. (You need /\. instead of /\
because you want to maintain the same initial state for each item of
the result. Also, I believe that /\. is O(n) while /\ is O(n^2) in the
general case and only O(n) where special code exists.)
Or, as you had initially suggested, replace that 12*# with 144*#
(That said, note also that what I have proposed here is an
optimization - and one should never concern oneself with optimizations
until after they have the code working properly.
Thanks,
--
Raul
On Fri, Apr 17, 2015 at 3:09 PM, 'Pascal Jasmin' via Programming
<[email protected]> wrote:
> can visualize this as a logo robot that moves 3 spaces at a time in the
> direction of a clockface. It moves like a chess knight for directions that
> are not 12 3 6 9.
>
> boxscan =: ((&.>)/)(>@:)
> move12 =: (12 | [ + {:@]) ,~ }:@:] + (12 2$0 3 1 2 2 1 3 0 2 _1 1 _2 0 _3 _1
> _2 _2 _1 _3 0 _2 1 _1 2) {~ 12 | [ + {:@]
>
> require 'plot'
>
> draw =: 3 : 'plot ;/ |: 2{."1 (],[move12{:@])boxscan (< ,: 0 0 0),~ |. ;/
> ($~12*#) y'
>
> for non repeating patterns, can change the 12*# to 144*#
>
> the easiest patterns to understand
> draw 1
> draw 3
>
> some cool patterns
>
>
> draw 1 4
> draw 3 2 6 1 4 11
> draw 1 3 4 3 11
> draw 1 5 10 4 2
> ----------------------------------------------------------------------
> 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