Anonymous user
N-queens problem: Difference between revisions
→{{header|D}}
(→Alternate Fortran 77 solution: + output) |
|||
Line 803:
=={{header|D}}==
From the C solution.
<lang d>import std.stdio: write, writeln
enum int SIDE = 8;
int[SIDE]
nothrow bool unsafe(int y) {
immutable int x =
foreach (i; 1 .. y+1) {
int t =
if ((t == x) || (t == x - i) || (t == x + i))
return true;
Line 819:
}
void
static int s = 0;
foreach (y; 0 .. SIDE) {
foreach (x; 0 .. SIDE)
write(
writeln(
}
}
Line 831:
void main() {
int y = 0;
while (y >= 0) {
do {
} while (
if (y < (SIDE
} else
y--;
}
}</lang>
===Brute force version===▼
▲Brute force version
<lang d>auto nqueens(int base) {
int total = base * base;
|