--- a/progs/knight2.scala Thu Nov 03 01:05:20 2016 +0000
+++ b/progs/knight2.scala Sat Nov 05 17:11:47 2016 +0000
@@ -26,7 +26,7 @@
// non-circle tours
def tour(n: Int)(steps: List[Pos]): List[List[Pos]] = {
- if (steps.length == n * n) List(steps)
+ if (steps.length == n * n && moves(n)(steps.head).contains(steps.last)) List(steps)
else
(for (x <- moves(n)(steps.head).par; if (!steps.contains(x))) yield tour(n)(x :: steps)).toList.flatten
}
@@ -35,4 +35,5 @@
val n = 6
println(s"number simple tours: n = $n")
-println((for (i <- 0 until n; j <- 0 until n) yield tour(n)(List((i, j)))).flatten.distinct.size)
+println(tour(n)(List((1,1))).distinct.size)
+//println((for (i <- 0 until n; j <- 0 until n) yield tour(n)(List((i, j)))).flatten.distinct.size)