queens6e=: 3 : 0
p=. perm y
c=. comb2 y
p #~ (c{"1/p) */ .~:&(|@-/) c
)
perm =: ! A.&i. ]
comb2 =: |:@(</"1 # ])@(, #: [EMAIL PROTECTED])~
mask =: {"1/ */ .~:&(|@-/) [
queens6=: comb2 (] #~ mask) perm
q=: queens6 f.
q
|:@(</"1 # ])@(, #: [EMAIL PROTECTED])~ (] #~ {"1/ */ .~:&(|@-/) [) ! A.&i. ]
# 5!:5 <'q'
64
# ' ' -.~ 5!:5 <'q'
51
There is 1 essential blank (the one in */ .~:),
so if non-essential blanks are removed the length is 52.
----- Original Message -----
From: Roger Hui <[EMAIL PROTECTED]>
Date: Sunday, April 6, 2008 17:17
Subject: Re: [Jgeneral] How readable is J?
To: General forum <[email protected]>
> If conciseness is a primary concern then the following
> is worthy of consideration. n>1.
>
> queens4=: 3 : 0
> p=. perm y
> c=. comb2 y
> p #~ (c{"_ 1 p) */ .~:&(|@:(-/"1)) c
> )
>
> perm =: [EMAIL PROTECTED] A. i.
> comb2 =: [: ; i.@<: ,.&.> <\.@(i.&.<:)
> mask =: {"_ 1 */ .~:&(|@:(-/"1)) [
> queens5=: comb2 (] #~ mask) perm
>
> queens5 f.
> ([: ; i.@<: ,.&.> <\.@(i.&.<:)) (] #~ {"_ 1 */
> .~:&(|@:(-/"1)) [) [EMAIL PROTECTED] A. i.
> q=: queens5 f.
> # 5!:5 <'q'
> 76
> # ' '-.~ 5!:5 <'q'
> 62
>
> There are 2 essential blanks, so if non-essential blanks
> are removed then the length is 64.
>
> queens5 4
> 1 3 0 2
> 2 0 3 1
> queens5 5
> 0 2 4 1 3
> 0 3 1 4 2
> 1 3 0 2 4
> 1 4 2 0 3
> 2 0 3 1 4
> 2 4 1 3 0
> 3 0 2 4 1
> 3 1 4 2 0
> 4 1 3 0 2
> 4 2 0 3 1
> queens5 6
> 1 3 5 0 2 4
> 2 5 1 4 0 3
> 3 0 4 1 5 2
> 4 2 0 5 3 1
>
>
>
> ----- Original Message -----
> From: Raul Miller <[EMAIL PROTECTED]>
> Date: Sunday, April 6, 2008 15:10
> Subject: Re: [Jgeneral] How readable is J?
> To: General forum <[email protected]>
>
> > On Sun, Apr 6, 2008 at 11:39 AM, Devon McCormick
> > <[EMAIL PROTECTED]> wrote:
> > > Wait, it _is_ online:
> > > http://www.vector.org.uk/archive/v103/selfridge103_94.htm
> > (Ralph's one-liner
> > > solution to the N-Queens problem).
> >
> > Interesting.
> >
> > A J one-liner (transcribed, almost literally, from that explicit
> > solution in the J
> > wiki) was significantly shorter.
> >
> > Repeated here (but probably line wrapped by email):
> >
> > queens=:(((~.@,[EMAIL PROTECTED]"1[:,.]+"1
> > _(i:1)*/~(-
> i.)@{:@$)((#~+/"1)~,.,@[#*/@[EMAIL PROTECTED]@,@])])^:([EMAIL
> PROTECTED]))@(i.@,*)>
> > queens 4
> > 1 3 0 2
> > 2 0 3 1
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm