Anonymous user
N-queens problem: Difference between revisions
m
→{{header|REXX}}: used a better dithering when showing a queen on a black square.
m (→{{header|REXX}}: increased whitespace in the use of the OUTPUT template.) |
m (→{{header|REXX}}: used a better dithering when showing a queen on a black square.) |
||
Line 8,675:
say 'A solution for ' N " queens:"; g=substr( copies("╬═══", N) ,2); say
say pad translate('╔'g"╗", '╦', "╬") /*display the top rank (of the board).*/
line = '╠'g"╣";
bar = '║' ;
Bqueen =
Wqueen = ' 'queen" "
do rank=1 for N; if rank\==1 then say pad line; _= /*display sep for rank.*/
Line 8,705:
╔═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗
║ Q
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
╚═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╝
</pre>
{{out|output|text= when using '''20'''x'''20''' chessboard with the input of: <tt> 20 </tt>}}
<pre>
A solution for 20 queens:
╔═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗
║ Q ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▓▓▓║ ║░Q░║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║ ║▓▓▓║ ║▓▓▓║ Q ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▓▓▓║ Q ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║ ║▓▓▓║ ║░Q░║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║░Q░║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ Q ║▓▓▓║ ║▓▓▓║ ║▓▓▓║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ Q ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║░Q░║ ║▓▓▓║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ Q ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ Q ║▓▓▓║ ║▓▓▓║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║░Q░║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║░Q░║ ║▓▓▓║ ║▓▓▓║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║░Q░║ ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║░Q░║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ Q ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ Q ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ Q ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║ ║▓▓▓║ ║▓▓▓║ ║░Q░║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║░Q░║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║
╚═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╝
</pre>
|