mikhail_dvorkin icon

Nonograms solver stub

mikhail_dvorkin | PRO | 01/16/21 08:17:04 AM UTC | 0 ⭐ | 12370 👁️ | Never ⏰ | []
Kotlin |

1.13 KB

|

None

|

0 👍

/

0 👎

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"
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"
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"
 
fun main() {
    val nonogram = sample1
    val (rows, columns) = nonogram.split("|").map { part ->
        part.split(";").map { lineInfo -> lineInfo.split(" ").map { token -> token.toInt() } }
    }
    println("$rows")
    println("$columns")
    val height = rows.size
    val width = columns.size
    /**
     * 0 = we don't know
     * 1 = black cell
     * -1 = white cell
     */
    val field = List(height) { MutableList(width) { 0 } }
    print(field)
    while (field.any { row -> 0 in row }) {
        var improved = false
        for (i in field.indices) {
            val result = process(rows[i], field[i])
            // TODO: put result to field
        }
        for (j in field[0].indices) {
            val result = process(columns[j], field.map { row -> row[j] })
            // TODO: put result to field
        }
        if (!improved) break
    }
}
 
fun process(info: List<Int>, fieldLine: List<Int>) {
 
}
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎