http://www.jsoftware.com/jwiki/Essays/Symmetries_of_the_Square
presents a terse transformation from permutations to
boolean matrices (and vice versa). From there it's
only a short step to "diagrams". Thus:
queens=: (, #: I.@,@(</)&i.)~ (] #"1~ [ */@:~:&(|@-/) {)&.|: ! A.&i. ]
t=: queens 8
$t
92 8
0{t
0 4 7 5 2 6 1 3
({=) 0{t
1 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 1
0 0 0 0 0 1 0 0
0 0 1 0 0 0 0 0
0 0 0 0 0 0 1 0
0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0
'.Q' {~ ({=) 0{t
Q.......
....Q...
.......Q
.....Q..
..Q.....
......Q.
.Q......
...Q....
boards=: '.Q' {~ ({=)"1 t
$ boards
92 8 8
0 91{boards
Q.......
....Q...
.......Q
.....Q..
..Q.....
......Q.
.Q......
...Q....
.......Q
...Q....
Q.......
..Q.....
.....Q..
.Q......
......Q.
....Q...
----- Original Message -----
From: Tracy Harms <[EMAIL PROTECTED]>
Date: Tuesday, April 8, 2008 15:49
Subject: [Jgeneral] board diagrams for n-queens problem
To: [email protected]
> Ralph G Selfridge wrote:
>
> > Let me add that the APL finds ALL solutions, no rotations or
> > symmetries, and written to print out on a typewriter. Somewhere
> > in the code I think I have page width (quad PW), so that as many
> > solutions as possible print across the page. Further you get a
> > picture of the board, not just coordinate pairs.
> > I'll make no attempt to get this to the forum.
> > Ralph S
>
> This inspired me to write a verb that creates diagrams from
> solution-permutations.
>
> NB. queens coded by Roger Hui; see N-queens essay
> on the J wiki.
> queens=: (, #: I.@,@(</)&i.)~ (] #"1~ [
> */@:~:&(|@-/) {)&.|: ! A.&i. ]
> $ queens 8
> 92 8
> 0 91 { queens 8
> 0 4 7 5 2 6 1 3
> 7 3 0 2 5 1 6 4
> boards=:' .Q'{~(~:/~8$0 1) >."2 2 (#&0 , 2 , 7&- #
> 0:)"0 queens 8
> $ boards
> 92 8 8
> 0 91 { boards
> Q. . . .
> . . Q .
> . . . Q
> . . .Q.
> .Q. . .
> . . . Q
> Q . . .
> . .Q. .
>
> . . . Q
> . .Q. .
> Q. . . .
> . Q . .
> . . Q .
> .Q. . .
> . . .Q.
> . . Q .
>
> This verb does not provide the most interesting features of
> Ralph's one-liner, but I happen to not be interested in
> integrating display and solution into a single line, nor in
> maximizing how many diagrams can be printed on a page.
>
> The important thing for me, as an exercise, was doing this
> without either boxing or amending.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm