A crossword puzzle is a rectangular grid of empty squares and filled blocks. Each empty square at the leftmost edge of a horizontal run of more than one empty square is given a number, as is each empty square at the top of a vertical run. Only one number is given to an empty square that meets both criteria. The numbers are assigned starting from 1 in the leftmost numbered square in the top row and then proceeding from left to right in the top row with consecutive numbers assigned to the other numbered squares in the top row. The second row is then numbered from left to right starting with the next available number, and so forth.
A crossword puzzle then has clues to what words fit in each horizontal ("across") space and each vertical ("down") space. Although the clues are not given as input to the problem, we will refer to the combination of number and direction of each answer as a clue.
|
|
||||||
Complete the isValid method in the Crossword class, which determines if the given set of answers is valid. The answers are valid if and only if they give a complete answer for each clue and the across answers and the down answers fit together (an across answer can't put one character in a square if a down answer would put a different character in that square).
Only the locations of the empty squares in the puzzle are given, not the numbers. The Crossword class has the following methods for you to determine the locations of the empty squares:
The answers to check are given as an instance of the Answers class which is passed to isValid. The Answers class has the following methods:
The isValid method should return true if the answers are valid and false otherwise.