Yes, that worked. New board created, without changing the old board or the
move.

   board =: 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1
   move =: 0 2 5
   make_move =: ((+. *. -.@:*.) +./) (1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |.!.0~
3 1 $ -)
   board make_move move
0 1 0 1 1 1 1 1 1 1 1 1 1 1 1
   board
1 1 1 1 1 0 1 1 1 1 1 1 1 1 1
   move
0 2 5

I'll look it over in the morning, when I'm fresh, and see if I can grok why
you parenthesized as you did, and try out your suggestion about (15{.1).

I've programmed a solution to this in several languages already, most
recently Clojure. It's a nice way to learn one's way around in a new
language.

Thanks!

On Sat, May 27, 2017 at 10:35 PM, Raul Miller <[email protected]> wrote:

> Basically, you put the definition of f in parenthesis (though it
> already is, so no actual change needed there), and the definition of g
> in parenthesis.
>
> You can even get the interpreter to do this for you:
>
>    9!:3]5
>
>    make_move
> g f
>    make_move f.
> ((+. *. -.@:*.) +./) (1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |.!.0~ 3 1 $ -)
>
> Though, I would be tempted to replace 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> with (15{.1) in a definition.
>
> I hope this helps,
>
> --
> Raul
>
>
> On Sat, May 27, 2017 at 10:28 PM, Michael Rice <[email protected]>
> wrote:
> > NB. 15 position peg solitaire
> > NB. The board (position 5 initially vacant)
> >
> > NB.         0
> > NB.       1   2
> > NB.      3  4   5
> > NB.    6  7   8   9
> > NB.  10 11 12  13 14
> >
> >    xor =: ((+.)*.(-.@:*.))
> >    board =: 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1  NB. 0s for vacant, 1s occupied
> >    board
> > 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1
> >    move =: 0 2 5
> >    move
> > 0 2 5
> >    board xor +./((1 0 0 0 0 0 0 0 0 0 0 0 0 0 0) |.!.0~ 3 1 $ -) move
> > 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1  NB. The desired result, a new board
> >    f =: ((1 0 0 0 0 0 0 0 0 0 0 0 0 0 0) |.!.0~ 3 1 $ -)
> >    f move
> > 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> > 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
> > 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
> >    +./f move
> > 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0  NB. Move 0 2 5 expressed as 15 element
> > binary array
> >    board xor +./f move
> > 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1  NB. Again, the desired result
> >    board                       NB. Both board and move unchanged
> > 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1
> >    move
> > 0 2 5
> >    g =: xor +./
> >    make_move =: g f
> >    board make_move move
> > 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1  NB. Again, the desired result
> >
> > ++++++++++++++++++++++++++++++++++
> >
> > The question: How to write make_move without creating subfunctions f and
> g?
> >
> > I've tried several definition variations and keep getting 'length error'
> > messages upon usage.
> >
> > One example:
> >    make_move =: xor+./((1 0 0 0 0 0 0 0 0 0 0 0 0 0 0) |.!.0~ 3 1 $ -)
> >    board make_move move
> > |length error: make_move
> > ----------------------------------------------------------------------
> > 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

Reply via email to