Question: So tis is code for 1D 8 queens no goto, but done. by brute force. I completely understand this program and some of the question

So tis is code for 1D 8 queens no goto, but done. by brute force. I completely understand this program and some of the question that are posted on this page. Sorry for the duplicate photos they're just attached like that.

So for the question where it asks to write the Ok function I already know it, its:

bool ok(int q[c], c){

for (int i = 0; i

if (q[i] == q[c]) || (abs(q[i] -q[c]) == (c - i)) {

return false;

}

}

return true;

However, I dont know how to do question a, which says what will be the 289th configuration. How do i calculate this? And lets say instead of the 1d* queens being a 8^8, what if it was a 4^4? How would i calculate it then? If i could get help with all the question then that would mean a lot. Thank you. Indepth response would be appreciated.

c So tis is code for 1D 8 queens no goto, butdone. by brute force. I completely understand this program and some of

// this function returns true if the array represents a solution // and false otherwise. You will be asked to write it below. \} The above code will generate 88 configurations for consideration. The first one generated is: and the last is: but we only print those for which the ok0 function returns true. If we got rid of the test on the line called "point 1" and instead just write: print(q,++count);//point1 we would end up printing all the 88 configurations. Explain fully how you got the answer here: Here are two questions about these configurations: a. What will be the configuration printed when the value of "count" printed is 289 ? (5 points) Write the configuration here: Explain fully how you got the answer here: b. If we go back to the original program and put if(ok(q))print(q,++count);//point1 back in, we will only get those configurations that represent the non-conflicting eight queens. Of course, the ok() function needs to work properly. Write the code for function ok( ) here: (15 points) bool ok(int q[l) { // check if the configuration passed in qll represents a solution b. If we go back to the original program and put if( ok(q) ) print(q, ++ count )=// point 1 back in, we will only get those configurations that represent the non-conflicting eight queens. Of course, the ok() function needs to work properly. Write the code for function ok0 here: (15 points) bool ok(int q[l){// check if the configuration passed in qll represents a solution

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!