Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 8 constant r
- create a r 1 + allot
- : nqueens
- a r 1 + erase
- 0{ s x y t }
- begin
- x 1 + to x
- r a x + c!
- begin
- s 1 + to s
- x to y
- begin y 1 > while
- y 1 - to y
- x a + c@ y a + c@ - to t
- t 0 = x y - t abs = or if
- 0 to y
- a x + dup c@ 1 - swap c!
- begin a x + c@ 0 = while
- x 1 - to x
- a x + dup c@ 1 - swap c!
- repeat
- then
- repeat
- y 1 = until
- x r = until
- s . ;
- 8 constant r
- create a r 1 + allot
- variable s
- : nqueens
- 0 s ! a r erase
- 0
- begin
- 1 + r over a + c!
- begin
- s @ 1 + s !
- dup
- begin dup 1 > while
- 1 -
- over a + c@ over a + c@ - abs
- dup 0 = 2over - rot = or if
- drop 0 over a + dup c@ 1 - swap c! swap
- begin dup a + c@ 0 = while
- 1 - dup a + dup c@ 1 - swap c!
- repeat
- swap
- then
- repeat
- 1 = until
- dup r = until
- drop
- s @ . ;
Advertisement
Add Comment
Please, Sign In to add comment