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

Reply via email to