Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/ * * * 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago