Advertisement
mikhail_dvorkin

Nonograms solver stub

Jan 16th, 2021
1,417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.13 KB | None | 0 0
  1. val sample1 = "4;2 1 1 1;9;3 3;6;2 2|2;2;2 1;5;1 3;1 1 1;3 1;1 4;5;1"
  2. val sample2 = "1;1 1 3;1 1 5;2 2 5;1 1 2 8;2 7 1;6 9 1;1 5 9 1;1 5 8;6 7;3 5|2;3 1 1;2 4;5;3 5;2 5;4;1;2;3;2;6;9;10;11;10;9;6;1 1;3"
  3. val sample3 = "3;5;3;2 1 2;1 1 4;1 2 1 5;1 1 7;1 7;5;3;1 1;1 1;2|2;1 1;1 2;1 1;1 2;4 2;4;1 8;3 6 1;9;3 4;1 3;1"
  4.  
  5. fun main() {
  6.     val nonogram = sample1
  7.     val (rows, columns) = nonogram.split("|").map { part ->
  8.         part.split(";").map { lineInfo -> lineInfo.split(" ").map { token -> token.toInt() } }
  9.     }
  10.     println("$rows")
  11.     println("$columns")
  12.     val height = rows.size
  13.     val width = columns.size
  14.     /**
  15.      * 0 = we don't know
  16.      * 1 = black cell
  17.      * -1 = white cell
  18.      */
  19.     val field = List(height) { MutableList(width) { 0 } }
  20.     print(field)
  21.     while (field.any { row -> 0 in row }) {
  22.         var improved = false
  23.         for (i in field.indices) {
  24.             val result = process(rows[i], field[i])
  25.             // TODO: put result to field
  26.         }
  27.         for (j in field[0].indices) {
  28.             val result = process(columns[j], field.map { row -> row[j] })
  29.             // TODO: put result to field
  30.         }
  31.         if (!improved) break
  32.     }
  33. }
  34.  
  35. fun process(info: List<Int>, fieldLine: List<Int>) {
  36.  
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement