4 kyu

5x5 Nonogram Solver

431 of 544Avanta

Description:

Once you complete this kata, there is a 15x15 Version that you can try. And once you complete that, you can do the Multisize Version which goes up to 50x50.

Description

For this kata, you will be making a Nonogram solver. :)

If you don't know what Nonograms are, you can look at some instructions and also try out some Nonograms here.

For this kata, you will only have to solve 5x5 Nonograms. :)

Instructions

You need to complete the Nonogram class and the solve method:

class Nonogram:

    def __init__(self, clues):
        pass

    def solve(self):
        pass
public class Nonogram {

  public static int[][] solve(int[][][] clues) {
    //Your code here
  
    return null;
  }

}
fn solve_nonogram((top_clues, left_clues): ([&[u8]; 5], [&[u8]; 5])) -> [[u8; 5]; 5] {
    todo!()
}

You will be given the clues and you should return the solved puzzle. All the puzzles will be solveable so you will not need to worry about that. There will be exactly one solution to each puzzle.

The clues will be a tuple of the column clues, then the row clues, which will contain the individual clues. For example, for the Nonogram:

    |   |   | 1 |   |   |
    | 1 |   | 1 |   |   |
    | 1 | 4 | 1 | 3 | 1 |
-------------------------
  1 |   |   |   |   |   |
-------------------------
  2 |   |   |   |   |   |
-------------------------
  3 |   |   |   |   |   |
-------------------------
2 1 |   |   |   |   |   |
-------------------------
  4 |   |   |   |   |   |
-------------------------

The clues are on the top and the left of the puzzle, so in this case:

The column clues are: ((1, 1), (4,), (1, 1, 1), (3,), (1,)), and the row clues are: ((1,), (2,), (3,), (2, 1), (4,)). The column clues are given from left to right. If there is more than one clue for the same column, the upper clue is given first. The row clues are given from top to bottom. If there is more than one clue for the same row, the leftmost clue is given first.

Therefore, the clue given to the __init__ method would be (((1, 1), (4,), (1, 1, 1), (3,), (1,)), ((1,), (2,), (3,), (2, 1), (4,))). You are given the column clues first then the row clues second.

You should return a tuple of the rows as your answer. In this case, the solved Nonogram looks like:

    |   |   | 1 |   |   |
    | 1 |   | 1 |   |   |
    | 1 | 4 | 1 | 3 | 1 |
-------------------------
  1 |   |   | # |   |   |
-------------------------
  2 | # | # |   |   |   |
-------------------------
  3 |   | # | # | # |   |
-------------------------
2 1 | # | # |   | # |   |
-------------------------
  4 |   | # | # | # | # |
-------------------------

In the tuple, you should use 0 for a unfilled square and 1 for a filled square. Therefore, in this case, you should return:

((0, 0, 1, 0, 0),
 (1, 1, 0, 0, 0),
 (0, 1, 1, 1, 0),
 (1, 1, 0, 1, 0),
 (0, 1, 1, 1, 1))

Good Luck!!

If there is anything that is unclear or confusing, just let me know :)

Algorithms
Logic
Games
Game Solvers

Similar Kata:

Stats:

CreatedDec 30, 2017
PublishedDec 30, 2017
Warriors Trained3734
Total Skips918
Total Code Submissions5501
Total Times Completed544
Python Completions431
Java Completions92
Rust Completions32
Total Stars373
% of votes with a positive feedback rating97% of 119
Total "Very Satisfied" Votes113
Total "Somewhat Satisfied" Votes6
Total "Not Satisfied" Votes0
Total Rank Assessments3
Average Assessed Rank
4 kyu
Highest Assessed Rank
3 kyu
Lowest Assessed Rank
5 kyu
Ad
Contributors
  • Avanta Avatar
  • matthewmoppett Avatar
  • Voile Avatar
  • joshua082390 Avatar
  • Awesome A.D. Avatar
Ad