progs/sudoku.scala
author Christian Urban <urbanc@in.tum.de>
Fri, 16 Aug 2019 08:45:21 +0100
changeset 277 acaf2099406a
parent 268 e43f7e92ba26
child 301 c3b33c709696
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
268
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
// Sudoku
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
//========
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
object Sudoku extends App { 
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
import scala.collection.parallel.CollectionConverters._
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
type Pos = (Int, Int)
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
val emptyValue = '.'
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
val maxValue = 9
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
val allValues = "123456789".toList
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
val indexes = (0 to 8).toList
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
def empty(game: String) = game.indexOf(emptyValue)
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
def isDone(game: String) = empty(game) == -1 
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
def emptyPosition(game: String) : Pos = 
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
  (empty(game) % maxValue, empty(game) / maxValue)
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
def get_row(game: String, y: Int) = indexes.map(col => game(y * maxValue + col))
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
def get_col(game: String, x: Int) = indexes.map(row => game(x + row * maxValue))
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
def get_box(game: String, pos: Pos): List[Char] = {
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
    def base(p: Int): Int = (p / 3) * 3
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
    val x0 = base(pos._1)
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
    val y0 = base(pos._2)
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
    for (x <- (x0 until x0 + 3).toList;
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
         y <- (y0 until y0 + 3).toList) yield game(x + y * maxValue)
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
}         
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
//get_row(game0, 0)
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
//get_row(game0, 1)
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
//get_box(game0, (3,1))
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
def update(game: String, pos: Int, value: Char): String = 
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
  game.updated(pos, value)
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
def toAvoid(game: String, pos: Pos): List[Char] = 
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
  (get_col(game, pos._1) ++ get_row(game, pos._2) ++ get_box(game, pos))
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
def candidates(game: String, pos: Pos): List[Char] = 
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
  allValues.diff(toAvoid(game, pos))
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
//candidates(game0, (0, 0))
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
//def pretty(game: String): String = 
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
//  "\n" ++ (game.sliding(maxValue, maxValue).mkString("\n"))
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
def search(game: String): List[String] = {
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
  if (isDone(game)) List(game)
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
  else 
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
    candidates(game, emptyPosition(game)).par.
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
      map(c => search(update(game, empty(game), c))).toList.flatten
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
}
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
// two easy games
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
val game0 = """.14.6.3..
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
              |62...4..9
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
              |.8..5.6..
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
              |.6.2....3
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
              |.7..1..5.
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
              |5....9.6.
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
              |..6.2..3.
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
              |1..5...92
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
              |..7.9.41.""".stripMargin.replaceAll("\\n", "")
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
val game1 = """23.915...
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
              |...2..54.
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
              |6.7......
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
              |..1.....9
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
              |89.5.3.17
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
              |5.....6..
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
              |......9.5
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
              |.16..7...
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
              |...329..1""".stripMargin.replaceAll("\\n", "")
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
// a game that is in the sligtly harder category
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
val game2 = """8........
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
              |..36.....
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
              |.7..9.2..
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
              |.5...7...
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
              |....457..
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
              |...1...3.
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
              |..1....68
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
              |..85...1.
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
              |.9....4..""".stripMargin.replaceAll("\\n", "")
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    92
// a game with multiple solutions
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    93
val game3 = """.8...9743
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    94
              |.5...8.1.
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    95
              |.1.......
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    96
              |8....5...
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    97
              |...8.4...
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    98
              |...3....6
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    99
              |.......7.
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   100
              |.3.5...8.
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   101
              |9724...5.""".stripMargin.replaceAll("\\n", "")
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   102
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   103
val hard_games = 
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   104
  List("85...24..72......9..4.........1.7..23.5...9...4...........8..7..17..........36.4.",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
       "..53.....8......2..7..1.5..4....53...1..7...6..32...8..6.5....9..4....3......97..",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   106
       "12..4......5.69.1...9...5.........7.7...52.9..3......2.9.6...5.4..9..8.1..3...9.4",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   107
       "...57..3.1......2.7...234......8...4..7..4...49....6.5.42...3.....7..9....18.....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   108
       "7..1523........92....3.....1....47.8.......6............9...5.6.4.9.7...8....6.1.",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   109
       "1....7.9..3..2...8..96..5....53..9...1..8...26....4...3......1..4......7..7...3..",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   110
       "1...34.8....8..5....4.6..21.18......3..1.2..6......81.52..7.9....6..9....9.64...2",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   111
       "...92......68.3...19..7...623..4.1....1...7....8.3..297...8..91...5.72......64...",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   112
       ".6.5.4.3.1...9...8.........9...5...6.4.6.2.7.7...4...5.........4...8...1.5.2.3.4.",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   113
       "7.....4...2..7..8...3..8.799..5..3...6..2..9...1.97..6...3..9...3..4..6...9..1.35",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   114
       "....7..2.8.......6.1.2.5...9.54....8.........3....85.1...3.2.8.4.......9.7..6....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
//       "4.....8.5.3..........7......2.....6.....8.4......1.......6.3.7.5..2.....1.4......",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
       "52...6.........7.13...........4..8..6......5...........418.........3..2...87.....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
       "6.....8.3.4.7.................5.4.7.3..2.....1.6.......2.....5.....8.6......1....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
       "48.3............71.2.......7.5....6....2..8.............1.76...3.....4......5....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
//       "....14....3....2...7..........9...3.6.1.............8.2.....1.4....5.6.....7.8...",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
       "......52..8.4......3...9...5.1...6..2..7........3.....6...1..........7.4.......3.",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
       "6.2.5.........3.4..........43...8....1....2........7..5..27...........81...6.....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
       ".524.........7.1..............8.2...3.....6...9.5.....1.6.3...........897........",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
       "6.2.5.........4.3..........43...8....1....2........7..5..27...........81...6.....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
       ".923.........8.1...........1.7.4...........658.........6.5.2...4.....7.....9.....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
       "6..3.2....5.....1..........7.26............543.........8.15........4.2........7..",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
       ".6.5.1.9.1...9..539....7....4.8...7.......5.8.817.5.3.....5.2............76..8...",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   127
       "..5...987.4..5...1..7......2...48....9.1.....6..2.....3..6..2.......9.7.......5..",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
       "3.6.7...........518.........1.4.5...7.....6.....2......2.....4.....8.3.....5.....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
       "1.....3.8.7.4..............2.3.1...........958.........5.6...7.....8.2...4.......",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
       "6..3.2....4.....1..........7.26............543.........8.15........4.2........7..",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
       "....3..9....2....1.5.9..............1.2.8.4.6.8.5...2..75......4.1..6..3.....4.6.",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
       "45.....3....8.1....9...........5..9.2..7.....8.........1..4..........7.2...6..8..",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
       ".237....68...6.59.9.....7......4.97.3.7.96..2.........5..47.........2....8.......",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
       "..84...3....3.....9....157479...8........7..514.....2...9.6...2.5....4......9..56",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
       ".98.1....2......6.............3.2.5..84.........6.........4.8.93..5...........1..",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
       "..247..58..............1.4.....2...9528.9.4....9...1.........3.3....75..685..2...",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   137
//       "4.....8.5.3..........7......2.....6.....5.4......1.......6.3.7.5..2.....1.9......",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   138
       ".2.3......63.....58.......15....9.3....7........1....8.879..26......6.7...6..7..4",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   139
       "1.....7.9.4...72..8.........7..1..6.3.......5.6..4..2.........8..53...7.7.2....46",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   140
       "4.....3.....8.2......7........1...8734.......6........5...6........1.4...82......",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   141
       ".......71.2.8........4.3...7...6..5....2..3..9........6...7.....8....4......5....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   142
       "6..3.2....4.....8..........7.26............543.........8.15........8.2........7..",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   143
       ".47.8...1............6..7..6....357......5....1..6....28..4.....9.1...4.....2.69.",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   144
       "......8.17..2........5.6......7...5..1....3...8.......5......2..4..8....6...3....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   145
       "38.6.......9.......2..3.51......5....3..1..6....4......17.5..8.......9.......7.32",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   146
       "...5...........5.697.....2...48.2...25.1...3..8..3.........4.7..13.5..9..2...31..",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   147
       ".2.......3.5.62..9.68...3...5..........64.8.2..47..9....3.....1.....6...17.43....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   148
       ".8..4....3......1........2...5...4.69..1..8..2...........3.9....6....5.....2.....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   149
       "..8.9.1...6.5...2......6....3.1.7.5.........9..4...3...5....2...7...3.8.2..7....4",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   150
//       "4.....5.8.3..........7......2.....6.....5.8......1.......6.3.7.5..2.....1.8......",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   151
       "1.....3.8.6.4..............2.3.1...........958.........5.6...7.....8.2...4.......",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   152
       "1....6.8..64..........4...7....9.6...7.4..5..5...7.1...5....32.3....8...4........",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   153
       "249.6...3.3....2..8.......5.....6......2......1..4.82..9.5..7....4.....1.7...3...",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   154
       "...8....9.873...4.6..7.......85..97...........43..75.......3....3...145.4....2..1",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   155
//       "...5.1....9....8...6.......4.1..........7..9........3.8.....1.5...2..4.....36....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   156
       "......8.16..2........7.5......6...2..1....3...8.......2......7..3..8....5...4....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   157
       ".476...5.8.3.....2.....9......8.5..6...1.....6.24......78...51...6....4..9...4..7",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   158
       ".....7.95.....1...86..2.....2..73..85......6...3..49..3.5...41724................",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   159
       ".4.5.....8...9..3..76.2.....146..........9..7.....36....1..4.5..6......3..71..2..",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   160
       ".834.........7..5...........4.1.8..........27...3.....2.6.5....5.....8........1..",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   161
       "..9.....3.....9...7.....5.6..65..4.....3......28......3..75.6..6...........12.3.8",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   162
       ".26.39......6....19.....7.......4..9.5....2....85.....3..2..9..4....762.........4",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   163
       "2.3.8....8..7...........1...6.5.7...4......3....1............82.5....6...1.......",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   164
       "6..3.2....1.....5..........7.26............843.........8.15........8.2........7..",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   165
       "1.....9...64..1.7..7..4.......3.....3.89..5....7....2.....6.7.9.....4.1....129.3.",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   166
       ".........9......84.623...5....6...453...1...6...9...7....1.....4.5..2....3.8....9",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   167
       ".2....5938..5..46.94..6...8..2.3.....6..8.73.7..2.........4.38..7....6..........5",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   168
       "9.4..5...25.6..1..31......8.7...9...4..26......147....7.......2...3..8.6.4.....9.",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   169
       "...52.....9...3..4......7...1.....4..8..453..6...1...87.2........8....32.4..8..1.",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   170
       "53..2.9...24.3..5...9..........1.827...7.........981.............64....91.2.5.43.",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   171
       "1....786...7..8.1.8..2....9........24...1......9..5...6.8..........5.9.......93.4",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   172
       "....5...11......7..6.....8......4.....9.1.3.....596.2..8..62..7..7......3.5.7.2..",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   173
       ".47.2....8....1....3....9.2.....5...6..81..5.....4.....7....3.4...9...1.4..27.8..",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   174
       "......94.....9...53....5.7..8.4..1..463...........7.8.8..7.....7......28.5.26....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   175
       ".2......6....41.....78....1......7....37.....6..412....1..74..5..8.5..7......39..",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   176
       "1.....3.8.6.4..............2.3.1...........758.........7.5...6.....8.2...4.......",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   177
       "2....1.9..1..3.7..9..8...2.......85..6.4.........7...3.2.3...6....5.....1.9...2.5",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   178
       "..7..8.....6.2.3...3......9.1..5..6.....1.....7.9....2........4.83..4...26....51.",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   179
       "...36....85.......9.4..8........68.........17..9..45...1.5...6.4....9..2.....3...",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   180
       "34.6.......7.......2..8.57......5....7..1..2....4......36.2..1.......9.......7.82",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   181
       "......4.18..2........6.7......8...6..4....3...1.......6......2..5..1....7...3....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
       ".4..5..67...1...4....2.....1..8..3........2...6...........4..5.3.....8..2........",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
       ".......4...2..4..1.7..5..9...3..7....4..6....6..1..8...2....1..85.9...6.....8...3",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
       "8..7....4.5....6............3.97...8....43..5....2.9....6......2...6...7.71..83.2",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
       ".8...4.5....7..3............1..85...6.....2......4....3.26............417........",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
       "....7..8...6...5...2...3.61.1...7..2..8..534.2..9.......2......58...6.3.4...1....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
       "......8.16..2........7.5......6...2..1....3...8.......2......7..4..8....5...3....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
       ".2..........6....3.74.8.........3..2.8..4..1.6..5.........1.78.5....9..........4.",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
       ".52..68.......7.2.......6....48..9..2..41......1.....8..61..38.....9...63..6..1.9",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
       "....1.78.5....9..........4..2..........6....3.74.8.........3..2.8..4..1.6..5.....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
       "1.......3.6.3..7...7...5..121.7...9...7........8.1..2....8.64....9.2..6....4.....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
       "4...7.1....19.46.5.....1......7....2..2.3....847..6....14...8.6.2....3..6...9....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
       "......8.17..2........5.6......7...5..1....3...8.......5......2..3..8....6...4....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
       "963......1....8......2.5....4.8......1....7......3..257......3...9.2.4.7......9..",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
       "15.3......7..4.2....4.72.....8.........9..1.8.1..8.79......38...........6....7423",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
       "..........5724...98....947...9..3...5..9..12...3.1.9...6....25....56.....7......6",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
       "....75....1..2.....4...3...5.....3.2...8...1.......6.....1..48.2........7........",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
       "6.....7.3.4.8.................5.4.8.7..2.....1.3.......2.....5.....7.9......1....",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
       "....6...4..6.3....1..4..5.77.....8.5...8.....6.8....9...2.9....4....32....97..1..",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
       ".32.....58..3.....9.428...1...4...39...6...5.....1.....2...67.8.....4....95....6.",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
       "...5.3.......6.7..5.8....1636..2.......4.1.......3...567....2.8..4.7.......2..5..",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
       ".5.3.7.4.1.........3.......5.8.3.61....8..5.9.6..1........4...6...6927....2...9..",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
       "..5..8..18......9.......78....4.....64....9......53..2.6.........138..5....9.714.",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
       "..........72.6.1....51...82.8...13..4.........37.9..1.....238..5.4..9.........79.",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
       "...658.....4......12............96.7...3..5....2.8...3..19..8..3.6.....4....473..",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
       ".2.3.......6..8.9.83.5........2...8.7.9..5........6..4.......1...1...4.22..7..8.9",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
       ".5..9....1.....6.....3.8.....8.4...9514.......3....2..........4.8...6..77..15..6.",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
       ".....2.......7...17..3...9.8..7......2.89.6...13..6....9..5.824.....891..........",
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
       "3...8.......7....51..............36...2..4....7...........6.13..452...........8..")
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
//search(game0).map(pretty)
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
//search(game1).map(pretty)
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
// for measuring time
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217
def time_needed[T](i: Int, code: => T) = {
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
  val start = System.nanoTime()
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
  for (j <- 1 to i) code
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
  val end = System.nanoTime()
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
  s"${(end - start) / i / 1.0e9} secs"
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
}
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
//search(game2).map(pretty)
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   225
//search(game3).distinct.length
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
println(time_needed(10, search(game0)))
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   227
println(time_needed(10, search(game1)))
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
println(time_needed(4, search(game2)))
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
println(time_needed(8, search(game3)))
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
for (i <- 0 until hard_games.length) {
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
    println("   " ++ hard_games(i))
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
    println(s"$i: ${time_needed(1, search(hard_games(i)))}")
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
}
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
e43f7e92ba26 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
}