33 lines
795 B
Plaintext
33 lines
795 B
Plaintext
-V BoardSize = 8
|
||
|
||
F underAttack(col, queens)
|
||
I col C queens
|
||
R 1B
|
||
L(x) queens
|
||
I abs(col - x) == queens.len - L.index
|
||
R 1B
|
||
R 0B
|
||
|
||
F solve(n)
|
||
V result = [[Int]()]
|
||
[[Int]] newSolutions
|
||
L(row) 1 .. n
|
||
L(solution) result
|
||
L(i) 1 .. BoardSize
|
||
I !underAttack(i, solution)
|
||
newSolutions.append(solution [+] [i])
|
||
swap(&result, &newSolutions)
|
||
newSolutions.clear()
|
||
R result
|
||
|
||
print(‘Solutions for a chessboard of size ’String(BoardSize)‘x’String(BoardSize))
|
||
print()
|
||
|
||
L(answer) solve(BoardSize)
|
||
L(col) answer
|
||
V row = L.index
|
||
I row > 0
|
||
print(‘ ’, end' ‘’)
|
||
print(Char(code' ‘a’.code + row)‘’col, end' ‘’)
|
||
print(end' I L.index % 4 == 3 {"\n"} E ‘ ’)
|