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 |