diff -r de59aa20a1dc -r ffce7b61b446 main_testing4/knight1.scala --- a/main_testing4/knight1.scala Mon Nov 08 01:16:13 2021 +0000 +++ b/main_testing4/knight1.scala Mon Nov 08 01:39:00 2021 +0000 @@ -1,7 +1,7 @@ // Part 1 about finding and counting Knight's tours //================================================== -object CW9a { // for preparing the jar +object M4a { // for preparing the jar type Pos = (Int, Int) // a position on a chessboard type Path = List[Pos] // a path...a list of positions @@ -43,8 +43,6 @@ List(( 1, 2),( 2, 1),( 2, -1),( 1, -2), (-1, -2),(-2, -1),(-2, 1),(-1, 2)).map(add_pair(x, _)) -// 1 mark - def legal_moves(dim: Int, path: Path, x: Pos): List[Pos] = moves(x).filter(is_legal(dim, path, _)) @@ -62,7 +60,6 @@ //assert(legal_moves(2, Nil, (0,0)) == List()) //assert(legal_moves(3, Nil, (0,0)) == List((1,2), (2,1))) -// 2 marks def tcount_tours(dim: Int, path: Path): Int = { if (path.length == dim * dim) 1 @@ -119,7 +116,6 @@ } */ -// 1 mark def first(xs: List[Pos], f: Pos => Option[Path]): Option[Path] = xs match { case Nil => None @@ -136,8 +132,6 @@ //first(List((1, 0),(2, 0),(3, 0)), foo) -// 1 mark - def tfirst_tour(dim: Int, path: Path): Option[Path] = { if (path.length == dim * dim) Some(path) else @@ -157,7 +151,7 @@ // 15 secs for 8 x 8 //val ts1 = time_needed(0,first_tour(8, List((0, 0))).get) -//val ts1 = time_needed(0,first_tour(8, List((1, 1))).get) +//??val ts1 = time_needed(0,first_tour(8, List((1, 1))).get) // no result for 4 x 4 //val ts2 = time_needed(0, first_tour(4, List((0, 0))))