main_marking4/knight1.scala
author Christian Urban <christian.urban@kcl.ac.uk>
Mon, 08 Nov 2021 01:39:00 +0000
changeset 403 ffce7b61b446
parent 391 0930e4555b60
child 424 daf561a83ba6
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
391
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     1
// Part 1 about finding and counting Knight's tours
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     2
//==================================================
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     3
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     4
object CW9a {   // for preparing the jar
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     5
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     6
type Pos = (Int, Int)    // a position on a chessboard 
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     7
type Path = List[Pos]    // a path...a list of positions
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     8
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     9
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    10
// for measuring time in the JAR
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    11
def time_needed[T](code: => T) : T = {
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    12
  val start = System.nanoTime()
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    13
  val result = code
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    14
  val end = System.nanoTime()
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    15
  println(f"Time needed: ${(end - start) / 1.0e9}%3.3f secs.")
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    16
  result
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    17
}
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    18
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    19
// for printing a board
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    20
def print_board(dim: Int, path: Path): Unit = {
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    21
  println()
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    22
  for (i <- 0 until dim) {
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    23
    for (j <- 0 until dim) {
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    24
      print(f"${path.reverse.indexOf((j, dim - i - 1))}%3.0f ")
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    25
    }
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    26
    println()
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    27
  } 
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    28
}
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    29
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    30
def is_legal(dim: Int, path: Path, x: Pos): Boolean = 
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    31
  0 <= x._1 && 0 <= x._2 && x._1 < dim && x._2 < dim && !path.contains(x)
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    32
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    33
// testcases
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    34
//assert(is_legal(8, Nil, (3, 4)) == true)
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    35
//assert(is_legal(8, List((4, 1), (1, 0)), (4, 1)) == false)
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    36
//assert(is_legal(2, Nil, (0, 0)) == true)
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    37
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    38
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    39
def add_pair(x: Pos, y: Pos): Pos = 
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    40
  (x._1 + y._1, x._2 + y._2)
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    41
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    42
def moves(x: Pos): List[Pos] = 
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    43
  List(( 1,  2),( 2,  1),( 2, -1),( 1, -2),
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    44
       (-1, -2),(-2, -1),(-2,  1),(-1,  2)).map(add_pair(x, _))
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    45
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    46
// 1 mark
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    47
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    48
def legal_moves(dim: Int, path: Path, x: Pos): List[Pos] = 
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    49
  moves(x).filter(is_legal(dim, path, _))
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    50
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    51
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    52
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    53
// testcases
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    54
//assert(legal_moves(8, Nil, (2,2)) == 
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    55
//  List((3,4), (4,3), (4,1), (3,0), (1,0), (0,1), (0,3), (1,4)))
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    56
//assert(legal_moves(8, Nil, (7,7)) == List((6,5), (5,6)))
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    57
//assert(legal_moves(8, List((4,1), (1,0)), (2,2)) == 
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    58
//  List((3,4), (4,3), (3,0), (0,1), (0,3), (1,4)))
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    59
//assert(legal_moves(8, List((6,6)), (7,7)) == List((6,5), (5,6)))
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    60
//assert(legal_moves(8, Nil, (0,1)) == List((1,3), (2,2), (2,0)))
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    61
//assert(legal_moves(1, Nil, (0,0)) == List())
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    62
//assert(legal_moves(2, Nil, (0,0)) == List())
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    63
//assert(legal_moves(3, Nil, (0,0)) == List((1,2), (2,1)))
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    64
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    65
// 2 marks
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    66
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    67
def tcount_tours(dim: Int, path: Path): Int = {
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    68
  if (path.length == dim * dim) 1
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    69
  else 
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    70
    (for (x <- legal_moves(dim, path, path.head)) yield tcount_tours(dim, x::path)).sum
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    71
}
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    72
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    73
def count_tours(dim: Int, path: Path) =
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    74
  time_needed(tcount_tours(dim: Int, path: Path))
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    75
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    76
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    77
def tenum_tours(dim: Int, path: Path): List[Path] = {
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    78
  if (path.length == dim * dim) List(path)
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    79
  else 
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    80
    (for (x <- legal_moves(dim, path, path.head)) yield tenum_tours(dim, x::path)).flatten
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    81
}
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    82
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    83
def enum_tours(dim: Int, path: Path) =
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    84
  time_needed(tenum_tours(dim: Int, path: Path))
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    85
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    86
// test cases
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    87
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    88
/*
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    89
def count_all_tours(dim: Int) = {
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    90
  for (i <- (0 until dim).toList; 
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    91
       j <- (0 until dim).toList) yield count_tours(dim, List((i, j)))
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    92
}
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    93
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    94
def enum_all_tours(dim: Int): List[Path] = {
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    95
  (for (i <- (0 until dim).toList; 
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    96
        j <- (0 until dim).toList) yield enum_tours(dim, List((i, j)))).flatten
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    97
}
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    98
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    99
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   100
println("Number of tours starting from (0, 0)")
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   101
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   102
for (dim <- 1 to 5) {
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   103
  println(s"${dim} x ${dim} " + time_needed(0, count_tours(dim, List((0, 0)))))
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   104
}
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   105
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   106
println("Number of tours starting from all fields")
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   107
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   108
for (dim <- 1 to 5) {
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   109
  println(s"${dim} x ${dim} " + time_needed(0, count_all_tours(dim)))
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   110
}
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   111
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   112
for (dim <- 1 to 5) {
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   113
  val ts = enum_tours(dim, List((0, 0)))
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   114
  println(s"${dim} x ${dim} ")   
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   115
  if (ts != Nil) {
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   116
    print_board(dim, ts.head)
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   117
    println(ts.head)
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   118
  }
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   119
}
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   120
*/
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   121
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   122
// 1 mark
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   123
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   124
def first(xs: List[Pos], f: Pos => Option[Path]): Option[Path] = xs match {
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   125
  case Nil => None
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   126
  case x::xs => {
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   127
    val result = f(x)
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   128
    if (result.isDefined) result else first(xs, f)
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   129
  }
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   130
}
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   131
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   132
// test cases
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   133
//def foo(x: (Int, Int)) = if (x._1 > 3) Some(List(x)) else None
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   134
//
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   135
//first(List((1, 0),(2, 0),(3, 0),(4, 0)), foo)
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   136
//first(List((1, 0),(2, 0),(3, 0)), foo)
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   137
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   138
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   139
// 1 mark
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   140
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   141
def tfirst_tour(dim: Int, path: Path): Option[Path] = {
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   142
  if (path.length == dim * dim) Some(path)
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   143
  else
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   144
    first(legal_moves(dim, path, path.head), (x:Pos) => tfirst_tour(dim, x::path))
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   145
}
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   146
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   147
def first_tour(dim: Int, path: Path) = 
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   148
  time_needed(tfirst_tour(dim: Int, path: Path))
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   149
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   150
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   151
/*
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   152
for (dim <- 1 to 8) {
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   153
  val t = first_tour(dim, List((0, 0)))
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   154
  println(s"${dim} x ${dim} " + (if (t == None) "" else { print_board(dim, t.get) ; "" }))
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   155
}
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   156
*/
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   157
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   158
// 15 secs for 8 x 8
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   159
//val ts1 = time_needed(0,first_tour(8, List((0, 0))).get)
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   160
//val ts1 = time_needed(0,first_tour(8, List((1, 1))).get)
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   161
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   162
// no result for 4 x 4
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   163
//val ts2 = time_needed(0, first_tour(4, List((0, 0))))
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   164
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   165
// 0.3 secs for 6 x 6
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   166
//val ts3 = time_needed(0, first_tour(6, List((0, 0))))
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   167
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   168
// 15 secs for 8 x 8
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   169
//time_needed(0, print_board(8, first_tour(8, List((0, 0))).get))
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   170
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   171
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   172
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   173
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   174
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   175
}
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   176
0930e4555b60 added main4 marking
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
   177