You could use -. for set difference, and ~.@, for union. You'd
probably want to use variables for * though.
Or, you could do
flip=: -. , -.~
legal_moves=: [ #~ 6 = 2 #. e.
1 2 3 4 5 (-.,-.~) 4 5 6
1 2 3 6
move_table ([ #~ 6 = 2 #. e.) 1 2 3 4 5
1 3 6
2 4 7
2 5 9
1 4 8
3 1 0
5 2 0
And, I guess you'd also need to modify search (I'll show the shuffling
variant, here):
search=:3 :0
((i.15) flip y) search i.0 3
:
NB. x: board; y: moves
if. 1=#x do. y return. end.
for_move. ({~ ?~@#) move_table legal_moves x do.
r=.(x flip move) search move,y
if. #r do. r return. end.
end.
i.0 3
)
So, ... yes, that would work.
Thanks,
--
Raul
On Mon, Jun 5, 2017 at 3:32 PM, Michael Rice <[email protected]> wrote:
> @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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm