Jump to content

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"╣"; dither= ""; ditherQ= '░' /*define a line (bar) for cell boundary*/
bar = '║' ; queen = "Q" /*kinds: horizontal, vertical, salad. */
Bqueen = ditherditherQ || queen || dither ditherQ /*glyph befitting a black─square queen.*/
Wqueen = ' 'queen" " /* " " " white─square " */
 
do rank=1 for N; if rank\==1 then say pad line; _= /*display sep for rank.*/
Line 8,705:
 
╔═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╗
║ Q ║▒▒▒║║▓▓▓║ ║▒▒▒║║▓▓▓║ ║▒▒▒║║▓▓▓║ ║▒▒▒║║▓▓▓║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▒▒▒║║▓▓▓║ ║▒▒▒║║▓▓▓║ ║▒Q▒║║░Q░║ ║▒▒▒║║▓▓▓║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▒▒▒║║▓▓▓║ ║▒▒▒║║▓▓▓║ ║▒▒▒║║▓▓▓║ ║▒Q▒║║░Q░║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▒▒▒║║▓▓▓║ ║▒▒▒║║▓▓▓║ ║▒▒▒║║▓▓▓║ Q ║▒▒▒║║▓▓▓║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▒▒▒║║▓▓▓║ Q ║▒▒▒║║▓▓▓║ ║▒▒▒║║▓▓▓║ ║▒▒▒║║▓▓▓║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▒▒▒║║▓▓▓║ ║▒▒▒║║▓▓▓║ ║▒▒▒║║▓▓▓║ ║▒Q▒║║░Q░║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▒Q▒║║░Q░║ ║▒▒▒║║▓▓▓║ ║▒▒▒║║▓▓▓║ ║▒▒▒║║▓▓▓║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▒▒▒║║▓▓▓║ ║▒▒▒║║▓▓▓║ Q ║▒▒▒║║▓▓▓║ ║▒▒▒║║▓▓▓║
╚═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╝
</pre>
{{out|output|text=&nbsp; when using &nbsp; '''20'''x'''20''' &nbsp; chessboard with the input of: &nbsp; &nbsp; <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 ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ Q ║▓▓▓║ ║▓▓▓║
║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ Q ║▒▒▒║ ║▒▒▒║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║░Q░║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║
║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒Q▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║░Q░║ ║▓▓▓║ ║▓▓▓║
║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒Q▒║ ║▒▒▒║ ║▒▒▒║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║░Q░║ ║
║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒Q▒║ ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║░Q░║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║
║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒Q▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ Q ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║
║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ Q ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ Q ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║
║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ Q ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ Q ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║
║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ Q ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║ ║▓▓▓║ ║▓▓▓║ ║░Q░║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║
║ ║▒▒▒║ ║▒▒▒║ ║▒Q▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║
╠═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╬═══╣
║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║░Q░║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║▓▓▓║ ║
║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒Q▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║▒▒▒║ ║
╚═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╝
</pre>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.