Yes, I tend to agree.  
Brian’s enquiry limits the choice to 8 out of the 24 perms, so filter on all is 
eminently simplest.

It was, however, quite interesting to (a) find that (any) one solution can 
spawn the other 7 by rotations and reverses, and (b) find a constructive 
method, albeit rather naive, for finding one solution.

I wondered earlier, but didn’t ask until now, why J was necessary for such a 
small problem.  Has Brian got a monster version of this teaser lurking in the 
murky shadows?

Cheers,

Mike


Sent from my iPad

> On 26 May 2020, at 15:08, David Lambert <[email protected]> wrote:
> 
> For small sets I'd start with the permutations, then select those I like.
> This shows two anti-selectors, sum of pairs equal 3, and in r2 the bad guys
> are directly spelled.
> 
> 
>   permutations=: A.&i.~ !
>   Filter=: "1(#~`)(`:6)
>   restrictions=: 1 (-.@e.) 3 = 2&(+/\)  NB. 1 where none of the length 2
> infix sums equal 3
> 
>   restrictions Filter permutations 4
> 0 1 3 2
> 0 2 3 1
> 1 0 2 3
> 1 3 2 0
> 2 0 1 3
> 2 3 1 0
> 3 1 0 2
> 3 2 0 1
> 
>   NB. directly enter those I don't want
>   r2=: 1 -.@e. [: , (>0 3;1 2;2 1;3 0)&(E."1)
>   (r2 Filter -: restrictions Filter)@:permutations 4
> 1
> 
>> Am 25.05.20 um 13:47 schrieb Brian Schott:
>> I want all permutations of  i. 4 for which 0 and 3 cannot be adjacent,
> nor can 1 and 2.
> ----------------------------------------------------------------------
> 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