Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
32
Task/N-queens-problem/11l/n-queens-problem.11l
Normal file
32
Task/N-queens-problem/11l/n-queens-problem.11l
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
-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 ‘ ’)
|
||||
Loading…
Add table
Add a link
Reference in a new issue