Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Im trying to validate skyscraper puzzles in an assignment, but I'm not sure how to write the method. The skyscraper numbers are in a 6
Im trying to validate skyscraper puzzles in an assignment, but I'm not sure how to write the method. The skyscraper numbers are in a 6 by 6 array, and I have to return a boolean if the array is valid by the rules or not.
Skyscraper is a puzzle where integer values from 1 through 4 are used to represent the height of skyscrapers on a 4 by 4 city grid, where a building of height 1 is the shortest. The outside of the 4 by 4 gri contain clue values. These values also range from 1 through 4 and represent the number of buildings that can be seen from a given row or column in the city grid. Each row and column of the city grid must not contain two buildings that are the same height for a solution to be valid. More specifically, each row and column must contain buildings with heights 1 through 4 . The rules for the values in the skyscraper grid are a little like those of Sudoku, for those that have played that. The image shows below on the left is an empty city grid with clues to the left with a completed city grid to the right that satisfies the clues given on the left. Your task is to write a program that reads from an input file whose name is specified as a command line argument. The file will contain data on one or more complete skyscrapers (including clues). For each skyscraper, you must determine if the skyscraper properly satisfies the clues. You do not have to worry about how to solve the puzzle. The solution of the puzzle is also provided in the green cells. The data in the file is guaranteed to be well-formed, so no error checking is required. The first line of data for a skyscraper will be the top clues for the 4 columns. The second line will start with the clue for the row looking from left to right, followed by the 4 skyscraper heights, followed by the clue for that row looking from right to left. Lines 3,4 , and 5 will be formatted as line 2. The final row will contain the bottom clues fo the 4 columns. All values will be separated by a single space. Each line of data in the file will end with a newline/carriage return (n). There will be no trailing lines in the file. As an example, the input file for the above example looks like this Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started