summaryrefslogtreecommitdiff
path: root/miralib/ex/queens1.m
diff options
context:
space:
mode:
Diffstat (limited to 'miralib/ex/queens1.m')
-rw-r--r--miralib/ex/queens1.m16
1 files changed, 16 insertions, 0 deletions
diff --git a/miralib/ex/queens1.m b/miralib/ex/queens1.m
new file mode 100644
index 0000000..79b52a8
--- /dev/null
+++ b/miralib/ex/queens1.m
@@ -0,0 +1,16 @@
+||This finds one solution to the eight queens problem, using a
+||different method from that of the previous script, "queens.m".
+||To run it, say
+|| output
+||This time the backtracking is programmed explicitly
+
+output = concat [c:shownum r++" "|(c,r)<-zip2 "rnbqkbnr" soln]
+soln = until full extend emptyboard
+extend board = until safe alter (addqueen board)
+addqueen board = 1:board
+emptyboard = []
+full board = # board=8
+alter (q:board) = q+1:board, if q<8
+ = alter board, otherwise ||backtrack
+safe (q:board) = and [~checks q board i|i<-index board]
+checks q board i = q=board!i \/ abs(q-board!i)=i+1