marking3/knight1_test3a.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 05 Nov 2021 17:20:01 +0000
changeset 397 085fefce672e
parent 326 e5453add7df6
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
326
e5453add7df6 updated
Christian Urban <urbanc@in.tum.de>
parents: 244
diff changeset
     1
import CW8a._
244
a359976a6f3e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
     2
//type Pos = (Int, Int)    // a position on a chessboard 
a359976a6f3e updated
Christian Urban <urbanc@in.tum.de>
parents: 243
diff changeset
     3
//type Path = List[Pos]    // a path...a list of positions
243
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
def count_all_tours_urban(dim: Int) = {
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
  for (i <- (0 until dim).toList; 
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
       j <- (0 until dim).toList) yield count_tours(dim, List((i, j)))
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
}
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
assert(count_all_tours_urban(1) == List(1))
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
assert(count_all_tours_urban(2) == List(0, 0, 0, 0))
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
assert(count_all_tours_urban(3) == List(0, 0, 0, 0, 0, 0, 0, 0, 0))
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
assert(count_all_tours_urban(4) == List(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
assert(count_all_tours_urban(5) == List(304, 0, 56, 0, 304, 0, 56, 0, 56, 0, 56, 0, 64, 0, 56, 0, 56, 0, 56, 0, 304, 0, 56, 0, 304))
9bb36426c781 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16