progs/knight1_sol.scala
changeset 85 fd3f8581ce85
parent 50 9891c9fac37e
child 86 f8a781322499
equal deleted inserted replaced
84:8b132f8de8c7 85:fd3f8581ce85
    31   List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4)))
    31   List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4)))
    32 assert(legal_moves(8, Nil, (7,7)) == List((6,5), (5,6)))
    32 assert(legal_moves(8, Nil, (7,7)) == List((6,5), (5,6)))
    33 assert(legal_moves(8, List((4,1), (1,0)), (2,2)) == 
    33 assert(legal_moves(8, List((4,1), (1,0)), (2,2)) == 
    34   List((3,4), (4,3), (3,0), (0,1), (0,3), (1,4)))
    34   List((3,4), (4,3), (3,0), (0,1), (0,3), (1,4)))
    35 assert(legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6)))
    35 assert(legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6)))
       
    36 assert(legal_moves(1, Nil, (0,0)) == List())
       
    37 assert(legal_moves(2, Nil, (0,0)) == List())
       
    38 assert(legal_moves(3, Nil, (0,0)) == List((1,2), (2,1)))
       
    39 
    36 
    40 
    37 def count_tours(dim: Int, path: Path): Int = {
    41 def count_tours(dim: Int, path: Path): Int = {
    38   if (path.length == dim * dim) 1
    42   if (path.length == dim * dim) 1
    39   else 
    43   else 
    40     (for (x <- legal_moves(dim, path, path.head)) yield count_tours(dim, x::path)).sum
    44     (for (x <- legal_moves(dim, path, path.head)) yield count_tours(dim, x::path)).sum