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/Arturo/n-queens-problem.arturo
Normal file
32
Task/N-queens-problem/Arturo/n-queens-problem.arturo
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
result: new []
|
||||
|
||||
queens: function [n, i, a, b, c][
|
||||
if? i < n [
|
||||
loop 1..n 'j [
|
||||
if all? @[
|
||||
not? contains? a j
|
||||
not? contains? b i+j
|
||||
not? contains? c i-j
|
||||
] ->
|
||||
queens n, i+1, a ++ @[j], b ++ @[i+j], c ++ @[i-j]
|
||||
|
||||
]
|
||||
]
|
||||
else [
|
||||
if n = size a ->
|
||||
'result ++ @[a]
|
||||
]
|
||||
]
|
||||
|
||||
BoardSize: 6
|
||||
|
||||
queens BoardSize, 0, [], [], []
|
||||
loop result 'solution [
|
||||
loop solution 'col [
|
||||
|
||||
line: new repeat "-" BoardSize
|
||||
line\[col-1]: `Q`
|
||||
print line
|
||||
]
|
||||
print ""
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue