Write Program Given Grid Finds Solution Satisfying Stated Criteria Input Come Keyboard Err Q43879568
Write a program that, givensuch a grid, finds a solution satisfying the stated criteria. Theinput will come from the keyboard. Error check for positive boardsizes from 4 to 15 only and check for a square matrix on input.Assume only one solution to a board. Let the user have the optionof running the program as many times if desired (check input).Output the solved grid with the erased cells with @’s and twospaces between each value. Use any data structure of your choice.Refer to the sample output below.
5 **). Hitori is a simple puzzle game played on an N * N grid of positive integers. The idea is simply to cross out integers in the grid (as few as possible) so that: • Any given number appears at most once in any given column or row; COSC 2436 520 The remaining (unerased) numbers form a single connected group of squares, so that any unerased square is reachable from any other unerased square by a path of unerased squares that are adjacent horizontally or vertically; • If a square is erased, its adjacent horizontal and vertical neighbors are not erased. So, given the initial grid (1), below, grid (2)is a solution. The other grids are not solutions for various reasons: (3)has two adjacent squares erased, (4)erases more squares than needed, and (5) breaks the unerased squares into unconnected groups. Of course, (1)itself is not a solution because it has duplicate numbers in several rows and columns. 1 2 5 3 4 2 2 2 3 6 3 5 2 4 5 1 – (1) 1 2 5 3 4 2 2 2 36 3 5 2 4 5 1 (2) 1 2 5 3 1 2 5 3 1 2 5 3 4 2 2 2 4 2 2 2 4 2 2 2 36 35 36 35 36 35 2 4 5 1 2 4 5 1 2 4 5 1 (3) (4) (5) Write a program that, given such a grid, finds a solution satisfying the stated criteria. The input will come from the keyboard. Error check for positive board sizes from 4 to 15 only and check for a square matrix on input. Assume only one solution to a board. Let the user have the option of running the program as many times if desired (check input). Output the solved grid with the erased cells with a’s and two spaces between each value. Use any data structure of your choice. Refer to the sample output below. Sample Run: Solved board: Enter the board size: 8 Enter a Hitori puzzle: 4 81 6 3 2 5 7 3 6 7 2 1 6 5 4 2 3 4 8 2 8 6 1 4 1 6 5 7 7 3 5 7 2 3 1 8 5 1 2 3 5 6 7 3 1 8 4 6 4 2 3 5 4 7 8 8 7 1 4 2 3 5 6 @ 3 @ 4 7 @ 6 8 8 6 3 1 @ 5 @ 7 @ 7 4 @ 3 6 2 1 6 2 @ 5 @ 7 3 4 3 1 2 7 8 @ 5 @ 2 @ 8 @ 5 1 4 3 @ 5 6 3 1 8 7 @ 7 4 1 @ 2 @ 8 6 Run again (Y/N)? y Enter the board size: 4 Enter a Hitori puzzle: Solved board: 1 253 4 2 2 2 3635 2 4 5 1 1 4 @ 2 2 @ 6 4 5 2 3 @ 3 @ 5 1 Run again (Y/N)? N Name the program: Hitorixx.java or Hitorixx.cpp, where XX are your initials Show transcribed image text 5 **). Hitori is a simple puzzle game played on an N * N grid of positive integers. The idea is simply to cross out integers in the grid (as few as possible) so that: • Any given number appears at most once in any given column or row; COSC 2436 520 The remaining (unerased) numbers form a single connected group of squares, so that any unerased square is reachable from any other unerased square by a path of unerased squares that are adjacent horizontally or vertically; • If a square is erased, its adjacent horizontal and vertical neighbors are not erased. So, given the initial grid (1), below, grid (2)is a solution. The other grids are not solutions for various reasons: (3)has two adjacent squares erased, (4)erases more squares than needed, and (5) breaks the unerased squares into unconnected groups. Of course, (1)itself is not a solution because it has duplicate numbers in several rows and columns.
1 2 5 3 4 2 2 2 3 6 3 5 2 4 5 1 – (1) 1 2 5 3 4 2 2 2 36 3 5 2 4 5 1 (2) 1 2 5 3 1 2 5 3 1 2 5 3 4 2 2 2 4 2 2 2 4 2 2 2 36 35 36 35 36 35 2 4 5 1 2 4 5 1 2 4 5 1 (3) (4) (5) Write a program that, given such a grid, finds a solution satisfying the stated criteria. The input will come from the keyboard. Error check for positive board sizes from 4 to 15 only and check for a square matrix on input. Assume only one solution to a board. Let the user have the option of running the program as many times if desired (check input). Output the solved grid with the erased cells with a’s and two spaces between each value. Use any data structure of your choice. Refer to the sample output below. Sample Run: Solved board: Enter the board size: 8 Enter a Hitori puzzle: 4 81 6 3 2 5 7 3 6 7 2 1 6 5 4 2 3 4 8 2 8 6 1 4 1 6 5 7 7 3 5 7 2 3 1 8 5 1 2 3 5 6 7 3 1 8 4 6 4 2 3 5 4 7 8 8 7 1 4 2 3 5 6 @ 3 @ 4 7 @ 6 8 8 6 3 1 @ 5 @ 7 @ 7 4 @ 3 6 2 1 6 2 @ 5 @ 7 3 4 3 1 2 7 8 @ 5 @ 2 @ 8 @ 5 1 4 3 @ 5 6 3 1 8 7 @ 7 4 1 @ 2 @ 8 6 Run again (Y/N)? y Enter the board size: 4 Enter a Hitori puzzle: Solved board: 1 253 4 2 2 2 3635 2 4 5 1 1 4 @ 2 2 @ 6 4 5 2 3 @ 3 @ 5 1 Run again (Y/N)? N Name the program: Hitorixx.java or Hitorixx.cpp, where XX are your initials
Expert Answer
Answer to Write a program that, given such a grid, finds a solution satisfying the stated criteria. The input will come from the k…
OR