I've not fully digested all of the fold rules yet, so I'll first focus
on building an insert version.

The key to using insert is building representing the expression which
would result from insert.

In other words, instead of
   state tomove moves
+-+-+----+
|C|M|PDNZ|
+-+-+----+

We could look at moves:

   moves
1 2 1
3 1 3
2 2 1
1 1 2

and construct a corresponding expression.

   1 1 2 move~ 2 2 1 move~ 3 1 3 move~ 1 2 1 move~ state
+-+-+----+
|C|M|PDNZ|
+-+-+----+

There's a type mismatch between the left and right arguments to move,
so instead of move~/ we would need to box the arguments maintain that
in our intermediate results.

That gives us |.state;<"1 moves as a starting point, move~&.>/ to
operate on them and ; to clean up at the end.

   ;move~&.>/|.state;<"1 moves
+-+-+----+
|C|M|PDNZ|
+-+-+----+

Fold would  let us dispense with this boxing mechanism, and ]F..v is
roughly equivalent to v/ and, testing, this works:

   state ]F..(move~) moves
+-+-+----+
|C|M|PDNZ|
+-+-+----+

And, I guess a rule here is that X ]F..V Y can be tested beforehand by
using V between items of Y with X as the rightmost such item.

I hope this makes sense,

-- 
Raul

On Tue, Dec 6, 2022 at 2:47 PM Brian Schott <schott.br...@gmail.com> wrote:
>
> I have successfully solved Day 5 using the following looping verb `tomove`
> but cannot craft a Fold version, and would like help.
>
> *[FYI I have included an attachment that seems to load and execute
> properly, but I could NOT get the email versions to load correctly,
> presumably because of some funny characters.]*
>
> tomove=: dyad define
> while. #y do.
> x=.x move {. y
> y =. }.y
> end.
> x
> )
>
>
> NB. The verb `move` for part 1 is very simple:
>
> move =: dyad define
> 'n f t'=. _1 1 1*y - 0 1 1
> take =. |.n{.>f{x
> left =. <n}.>f{x
> put =. <take,~>t{x
> (left,put) (f,t)}x
> )
>
> NB. the inputs are produced as follows.
>
> top =: 0 :0
>     [D]
> [N] [C]
> [Z] [M] [P]
>  1   2   3
> )
>
> state=.deb each ;/ |:|.}:1 5 9&{;._2 top
>
> bottom =: 0 :0
> move 1 from 2 to 1
> move 3 from 1 to 3
> move 2 from 2 to 1
> move 1 from 1 to 2
> )
> alpha =. a. {~97+i.26
> moves =. ".-.&alpha ;._2 bottom
>
> NB. finally the result is produced by the next phrase
>
> {:every state tomove moves
>
> --
> (B=) <-----my sig
> Brian Schott
> ----------------------------------------------------------------------
> 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