Question: / * * * Check if assigning value to houses [ h ] [ a ] is valid * / public boolean valid ( int

/**
* Check if assigning value to houses[h][a] is valid
*/
public boolean valid(int[][] houses, int h, int a, int value){
// Use each value one time per column
for (int i =0; i < houses.length; i++){
if (houses[i][a]== value){
return false;
}
}
// Provisional assignment
houses[h][a]= value;
// Check the constraints
boolean constraints = britLivesInRedHouse(houses)
&& swedeKeepsDogs(houses)
&& daneDrinksTea(houses);
// etc.
// Undo test assignment
houses[h][a]= NONE;
return
Start with only the britLivesInRedHouse constraint. Run your search and
verify that you can produce a solution with the Brit in the red house. The
other assignments will probably be incorrect, but thats okay.
Then add one more constraint, like swedeKeepsDogs. Run the solution again
and verify that youre now satisfying both constraints.
Continue, adding just one constraint at a time until you have all 15 in place.
Who owns the fish

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!