progs/knight2.scala
changeset 7 7a5a29a32568
parent 6 aae256985251
child 8 ab77f6006f1f
equal deleted inserted replaced
6:aae256985251 7:7a5a29a32568
    26 
    26 
    27 // non-circle tours
    27 // non-circle tours
    28 def tour(n: Int)(steps: List[Pos]): List[List[Pos]] = {
    28 def tour(n: Int)(steps: List[Pos]): List[List[Pos]] = {
    29   if (steps.length ==  n * n) List(steps)
    29   if (steps.length ==  n * n) List(steps)
    30   else 
    30   else 
    31     (for (x <- moves(n)(steps.head); if (!steps.contains(x))) yield tour(n)(x :: steps)).flatten
    31     (for (x <- moves(n)(steps.head).par; if (!steps.contains(x))) yield tour(n)(x :: steps)).toList.flatten
    32 }
    32 }
    33 
    33 
    34 //val n = 8
    34 //val n = 8
    35 val n = 6
    35 val n = 6
    36 println(s"number simple tours: n = $n")
    36 println(s"number simple tours: n = $n")