Guest User

Untitled

a guest
Jul 28th, 2025
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. 8 constant r
  2. create a r 1 + allot
  3.  
  4. : nqueens
  5. a r 1 + erase
  6. 0{ s x y t }
  7. begin
  8. x 1 + to x
  9. r a x + c!
  10. begin
  11. s 1 + to s
  12. x to y
  13. begin y 1 > while
  14. y 1 - to y
  15. x a + c@ y a + c@ - to t
  16. t 0 = x y - t abs = or if
  17. 0 to y
  18. a x + dup c@ 1 - swap c!
  19. begin a x + c@ 0 = while
  20. x 1 - to x
  21. a x + dup c@ 1 - swap c!
  22. repeat
  23. then
  24. repeat
  25. y 1 = until
  26. x r = until
  27. s . ;
  28.  
  29.  
  30.  
  31. 8 constant r
  32. create a r 1 + allot
  33. variable s
  34.  
  35. : nqueens
  36. 0 s ! a r erase
  37. 0
  38. begin
  39. 1 + r over a + c!
  40. begin
  41. s @ 1 + s !
  42. dup
  43. begin dup 1 > while
  44. 1 -
  45. over a + c@ over a + c@ - abs
  46. dup 0 = 2over - rot = or if
  47. drop 0 over a + dup c@ 1 - swap c! swap
  48. begin dup a + c@ 0 = while
  49. 1 - dup a + dup c@ 1 - swap c!
  50. repeat
  51. swap
  52. then
  53. repeat
  54. 1 = until
  55. dup r = until
  56. drop
  57. s @ . ;
Advertisement
Add Comment
Please, Sign In to add comment