"There ought to be a more elegant way of building move_table,"

I would replace the fragment   (,:|.&.>)(;1{.&.>~1+i.5)<;.1>:i.15  by
 |:(>:@:(+/\)(;|.)@:+&><\)i.5  or, if you prefer, by
 |:(>:@(+/\)(;|.)@:+&><\)i.5  .




On Sun, Jun 4, 2017 at 1:35 PM, Raul Miller <[email protected]> wrote:

> Actually, after further thought, I think I'd define some of your words
> this way:
>
> move_table=: <:(,|."1)(#~0<*/"1)~.,/,/_3&{.@/:~\"1(,|:"2)>(,:|.&.>)(;1{.&
> .>~1+i.5)<;.1>:i.15
>
> flip=: ~: (i.15)&e.
>
> legal_moves=: [ #~ 6 = 2 #. {
>
> There ought to be a more elegant way of building move_table, but I'm
> not sure I'm smart enough to come up with that.
>
> Anyways, I hope this helps...
>
> Thanks,
>
> --
> Raul
>
>
>
> On Sun, Jun 4, 2017 at 11:30 AM, Michael Rice <[email protected]> wrote:
> > Two things come to mind: 1) *reductio ad absurdum* and 2) a Dustin
> Hoffman
> > film, wherein he says to a man, "I going to explain something so you'll
> > understand it!" and then shoots him.
> >
> > I already had a function that does what I needed (see below) but was
> musing
> > about left/right parameter style, when one of the parameters remains
> > constant and the other changes "functionally" in the program.
> >
> > Just looking at your first "simplification," I can see I have a lot of
> > familiarization work to do. For example, what's the difference between
> >
> > 2 3 <@, 3 4 and 1 2 <@:, 3 4
> >
> > when the result is the same?
> >
> > Must be something subtle.
> >
> > =================
> >
> > Note: The moves marked with "<-" are moves to a known solution.
> >
> >
> > 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
> >
> >    move_table =: 36 3 $ 0 2 5 5 2 0 0 1 3 3 1 0 1 3 6 6 3 1 1 4 8 8 4 1
> 2 4
> > 7 7 4 2 2 5 9 9 5 2 3 6 10 10 6 3 3 7 12 12 7 3 3 4 5 5 4 3 4 7 11 11 7
> 4 4
> > 8 13 13 8 4 5 8 12 12 8 5 5 9 14 14 9 5 6 7 8 8 7 6 7 8 9 9 8 7 10 11 12
> 12
> > 11 10 11 12 13 13 12 11 12 13 14 14 13 12
> >    id =: e. i. 15
> >    flip =: (~: 3 : 'if. ((< & 2) @: #) y do. ({ & id) y else. (+./ @: ({
> &
> > id)) y end. ')
> >    legal_moves =: (#~ ((-: & 1 1 0)"1 @: ({~ & move_table)))
> >    board =: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
> >    board
> > 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
> >    board =: board flip 5
> >    board
> > 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1
> >    move_table legal_moves board
> >  0 2 5 <-
> >  3 4 5
> > 12 8 5
> > 14 9 5
> >    board =: board flip 0 2 5
> >    board
> > 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1
> >    move_table legal_moves board
> > 3 1 0 <-
> > 7 4 2
> > 9 5 2
> >    board =: board flip 3 1 0
> >    board
> > 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1
> >    move_table legal_moves board
> >  8 4 1
> >  7 4 2
> >  9 5 2
> > 10 6 3
> > 12 7 3
> >  5 4 3 <-
> >    board =: board flip 5 4 3
> >    board
> > 1 0 0 1 0 0 1 1 1 1 1 1 1 1 1
> >    move_table legal_moves board
> >  6 3 1 <-
> > 11 7 4
> > 13 8 4
> > 12 8 5
> > 14 9 5
> >    board =: board flip 6 3 1
> >    board
> > 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1
> >    move_table legal_moves board
> >  0 1 3 <-
> > 12 7 3
> > 11 7 4
> > 13 8 4
> > 12 8 5
> > 14 9 5
> >  8 7 6
> >    board =: board flip 0 1 3
> >    board
> > 0 0 0 1 0 0 0 1 1 1 1 1 1 1 1
> >    move_table legal_moves board
> > 11 7 4 <-
> > 13 8 4
> > 12 8 5
> > 14 9 5
> >  8 7 6
> >    board =: board flip 11 7 4
> >    board
> > 0 0 0 1 1 0 0 0 1 1 1 0 1 1 1
> >    move_table legal_moves board
> >  8  4  1
> >  3  4  5 <-
> > 12  8  5
> > 14  9  5
> >  9  8  7
> > 13 12 11
> >    board =: board flip 3 4 5
> >    board
> > 0 0 0 0 0 1 0 0 1 1 1 0 1 1 1
> >    move_table legal_moves board
> >  9  5  2 <-
> > 13  8  4
> >  9  8  7
> > 13 12 11
> >    board =: board flip 9 5 2
> >    board
> > 0 0 1 0 0 0 0 0 1 0 1 0 1 1 1
> >    move_table legal_moves board
> > 13  8  4
> > 12  8  5
> > 13 12 11 <-
> >    board =: board flip 13 12 11
> >    board
> > 0 0 1 0 0 0 0 0 1 0 1 1 0 0 1
> >    move_table legal_moves board
> > 10 11 12 <-
> >    board =: board flip 10 11 12
> >    board
> > 0 0 1 0 0 0 0 0 1 0 0 0 1 0 1
> >    move_table legal_moves board
> > 12 8 5 <-
> >    board =: board flip 12 8 5
> >    board
> > 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1
> >    move_table legal_moves board
> > 5 2 0
> > 2 5 9 <-
> >    board =: board flip 2 5 9
> >    board
> > 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1
> >    move_table legal_moves board
> > 14 9 5 <-
> >    board =: board flip 14 9 5
> >    board
> > 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
> >    move_table legal_moves board
> >
> >
> >
> >
> > On Sun, Jun 4, 2017 at 10:03 AM, Raul Miller <[email protected]>
> wrote:
> >
> >> Like this?
> >>
> >>    (#~ 5=2#.@:|])z
> >> 3 4 5
> >>
> >> --
> >> Raul
> >>
> >>
> >> On Sun, Jun 4, 2017 at 9:43 AM, Michael Rice <[email protected]>
> wrote:
> >> > How about
> >> >    1 0 1 0 1 0 (#~ ((-: & 0 1 0)"1 @: ({~ & z)))~ z
> >> > ?
> >> >
> >> > Odd, that's the KISS way, the way that always works, and the one way I
> >> > hadn't considered.
> >> >
> >> > On to your "simplifications."
> >> >
> >> > On Sat, Jun 3, 2017 at 10:16 PM, Louis de Forcrand <[email protected]>
> >> wrote:
> >> >
> >> >> How about
> >> >>    1 0 1 0 1 0 (#~ ((-: & 0 1 0)"1 @: ({~ & z)))~ z
> >> >> ?
> >> >> You can then "simplify":
> >> >>
> >> >> First the hook (and {~&z)
> >> >> ([ #~ -:&0 1 0"1@:(z&{)@])~
> >> >> ([ #~ -:&0 1 0"1@:(z&{)@])~
> >> >>
> >> >> Then ~ can be "distributed" over the resulting fork:
> >> >> [~ #~ -:&0 1 0"1@:(z&{)@(]~)
> >> >> ] #~ -:&0 1 0"1@:(z&{)@[
> >> >>
> >> >> You can keep going;
> >> >> From bonding to forks:
> >> >> ] #~ (] -: 0 1 0"_)"1@:(z { ])@[
> >> >> Composition and -: commutativity:
> >> >> ] #~ (0 1 0 -: ])"1@:(z { ]@[)
> >> >> Because 1=#$0 1 0:
> >> >> ] #~ (0 1 0 -:"1 ])@:(z { [)
> >> >> Trains:
> >> >> ] #~ (0 1 0 -:"1 ]@:(z { [))
> >> >> ] #~ 0 1 0 -:"1 ]@:(z { ])
> >> >> ] #~ 0 1 0 -:"1 z { [
> >> >>
> >> >> Can't get it any simpler.
> >> >>
> >> >> Cheers,
> >> >> Louis
> >> >>
> >> >> > On 4 Jun 2017, at 03:45, Michael Rice <[email protected]> wrote:
> >> >> >
> >> >> >   z (#~ ((-: & 0 1 0)"1 @: ({~ & z))) 1 0 1 0 1 0
> >> >>
> >> >> ------------------------------------------------------------
> ----------
> >> >> 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
> >>
> > ----------------------------------------------------------------------
> > 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