N-queens problem: Difference between revisions

Content added Content deleted
(Add Ecstasy example)
(Applesoft BASIC, added the BASIC header)
Line 1,381: Line 1,381:
[[image:N-Queens_SolutionBrowserGUI.png]]
[[image:N-Queens_SolutionBrowserGUI.png]]


=={{header|BBC BASIC}}==
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
{{trans|Java}}
<syntaxhighlight lang="basic"> 1 READ N,T,M,R(0): FOR Y = 0 TO M STEP 0: FOR L = 0 TO T STEP 0:R(Y) = R(Y) + T:X = R(Y):C = NOT Y: IF NOT C THEN FOR I = T TO Y:A = R(Y - I): IF NOT (A = X OR A = X - I OR A = X + I) THEN NEXT I:C = T
2 L = R(Y) > N OR C: NEXT L:D = - (R(Y) > N): IF NOT D AND Y < N THEN R(Y + T) = M:D = D + T
3 S = S + NOT D:Y = Y + D: NEXT Y: PRINT "THERE " MID$ ("AREIS",4 ^ (S = 1),3)" "S" SOLUTION" MID$ ("S",1,S < > 1)" FOR "N + T" X "N + T: DATA7,1,-1,-1</syntaxhighlight>
{{out}}
<pre>THERE ARE 92 SOLUTIONS FOR 8 X 8
</pre>
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
{{works with|BBC BASIC for Windows}}
The total number of solutions is displayed in the title bar and one solution is displayed. The code could be adapted to display a selected solution or multiple solutions.
The total number of solutions is displayed in the title bar and one solution is displayed. The code could be adapted to display a selected solution or multiple solutions.