@Raul MIller

Thanks.

Another way to model  board positions is with sets. A Common Lisp
implementation: the "*" captures the last output line, in this case the
current board, which begins with all positions full.

[1]> (defvar board '(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14))
BOARD
[2]> board
(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14)
[3]> (set-difference * '(5))          ;Open up position 5
(0 1 2 3 4 6 7 8 9 10 11 12 13 14)   ;Move 0 2 5 in two steps
[4]> (set-difference * '(0 2))             ;Empty 0 and 2
(1 3 4 6 7 8 9 10 11 12 13 14)
[5]> (union * '(5))                           ;Fill 5
(1 3 4 6 7 8 9 10 11 12 13 14 5)
[6]> (union (set-difference * '(3 1)) '(0))  ;Move 3 1 0 in one step
(4 6 7 8 9 10 11 12 13 14 5 0)

Could be a better way to do it in J. Just a thought.


On Mon, Jun 5, 2017 at 10:53 AM, Raul Miller <[email protected]> wrote:

> factorial=: !
>
> factorial=: (* $:@<:)`1:@.(1>])"0
>
> Or, if you prefer:
>
> factorial=: (* factorial@<:)`1:@.(1>])"0
>
> Note that (* $:@<:)`1:@.(1>])"0 is far less efficient than ! but at
> least it's less general.
>
> I hope this helps,
>
> --
> Raul
>
>
> On Mon, Jun 5, 2017 at 10:40 AM, Michael Rice <[email protected]> wrote:
> > Keep it simple, please.
> >
> > ---------------------------
> >
> > From "Learning J":
> >
> > *To compute the sum of a list of numbers, we have seen the verb +/ but
> let
> > us look at another way of defining a summing verb.*
> >
> > *The sum of an empty list of numbers is zero, and otherwise the sum is
> the
> > first item plus the sum of the remaining items. If we define three verbs,
> > to test for an empty list, to take the first item and to take the
> remaining
> > items:*
> >
> > *   empty =: # = 0:*
> > *   first =: {.*
> > *   rest  =: }.*
> >
> > *then the two cases to consider are:*
> >
> > *an empty list, in which case we apply the 0: function to return zero*
> >
> > *a non-empty list, in which case we want the first plus the sum of the
> > rest:*
> >
> > *   Sum =: (first + Sum @ rest) ` 0:  @. empty *
> >
> > *   Sum 1 1 2*
> > *4*
> > ----------------------------------------------------------------------
> > 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