progs/knight2.scala
changeset 43 ba4081c70de4
parent 42 a5106bc13db6
child 44 9cfa37c91444
equal deleted inserted replaced
42:a5106bc13db6 43:ba4081c70de4
    28 */
    28 */
    29 
    29 
    30 def tour(dim: Int, path: List[Pos]): Int = {
    30 def tour(dim: Int, path: List[Pos]): Int = {
    31   if (path.length == dim * dim) 1
    31   if (path.length == dim * dim) 1
    32   else 
    32   else 
    33     (for (x <- legal_moves(dim, path, path.head)) yield tour(dim, x::path)).sum
    33     (for (x <- legal_moves(dim, path, path.head).par) yield tour(dim, x::path)).sum
    34 }
    34 }
    35 
    35 
    36 //val n = 8
    36 //val n = 8
    37 val n = 6
    37 val n = 6
    38 println(s"number simple tours: n = $n")
    38 println(s"number simple tours: n = $n")
    39 
    39 
    40 //println(tour(n, List((0, 0))))
    40 println(tour(n, List((0, 0))))
    41 
    41 
       
    42 /*
    42 for (d <- 1 to 6) {
    43 for (d <- 1 to 6) {
    43   println(s"${d} x ${d} " + (for (i <- 0 until d; j <- 0 until d) yield tour(d, List((i, j)))).sum)
    44   println(s"${d} x ${d} " + (for (i <- 0 until d; j <- 0 until d) yield tour(d, List((i, j)))).sum)
    44 } 
    45 } 
       
    46 */