main_marking4/knight1_test3b.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Sat, 11 Mar 2023 22:01:53 +0000
changeset 463 0315d9983cd0
parent 424 daf561a83ba6
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
424
Christian Urban <christian.urban@kcl.ac.uk>
parents: 387
diff changeset
     1
import M4a._
386
e2170c91a9f2 added marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     2
//type Pos = (Int, Int)    // a position on a chessboard 
e2170c91a9f2 added marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     3
//type Path = List[Pos]    // a path...a list of positions
e2170c91a9f2 added marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     4
387
6282b88511d8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 386
diff changeset
     5
/*
386
e2170c91a9f2 added marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     6
def count_all_tours_urban(dim: Int) = {
e2170c91a9f2 added marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     7
  for (i <- (0 until dim).toList; 
e2170c91a9f2 added marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     8
       j <- (0 until dim).toList) yield count_tours(dim, List((i, j)))
e2170c91a9f2 added marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     9
}
387
6282b88511d8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 386
diff changeset
    10
*/
6282b88511d8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 386
diff changeset
    11
6282b88511d8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 386
diff changeset
    12
def count_all_tours_urban(dim: Int) = {
6282b88511d8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 386
diff changeset
    13
  for (i <- (0 until 3).toList; 
6282b88511d8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 386
diff changeset
    14
       j <- (0 until dim).toList) yield count_tours(dim, List((i, j)))
6282b88511d8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 386
diff changeset
    15
}
386
e2170c91a9f2 added marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    16
e2170c91a9f2 added marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    17
463
0315d9983cd0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 424
diff changeset
    18
import scala.concurrent._
0315d9983cd0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 424
diff changeset
    19
import scala.concurrent.duration._
0315d9983cd0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 424
diff changeset
    20
import ExecutionContext.Implicits.global
0315d9983cd0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 424
diff changeset
    21
import scala.language.postfixOps 
0315d9983cd0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 424
diff changeset
    22
0315d9983cd0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 424
diff changeset
    23
lazy val f = Future {
387
6282b88511d8 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 386
diff changeset
    24
assert(count_all_tours_urban(5) == List(304, 0, 56, 0, 304, 0, 56, 0, 56, 0, 56, 0, 64, 0, 56))
463
0315d9983cd0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 424
diff changeset
    25
}
386
e2170c91a9f2 added marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    26
463
0315d9983cd0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 424
diff changeset
    27
Await.result(f, 32 second)
0315d9983cd0 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 424
diff changeset
    28