Project 2: Eight Numbers in a Cross Write a program which allocates the integers 1-8 to...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Project 2: Eight Numbers in a Cross Write a program which allocates the integers 1-8 to the squares in the figure above, subject to the restrictions that no two adjacent squares contain consecutive integers. By adjacent we mean vertically, horizontally, or diagonally. Please provide both recursive solution and backtrack solution. Submission detail: Two independent cpp files should be submitted. 50 pt-Backtrack solution 50 pt - Recursive solution 8 number Eight Number in a Cross In the solution to this problem, use the backtracking scheme that we covered in class. Write a program which allocates the integers 1-8 to the squares in the figure above, subject to the restrictions that no two adjacent squares contain consecutive integers. By adjacent we mean vertically, horizontally, or diagonally. Eight Number in a Cross By-Hand Algorithm to. Obtain Adjacency Table 1) Label cross boxes arbitrarily from 0 through 7. 2) for each box i=0., 1.... 7: for each adjacent box k (such that k <i): add k to i's neighbor list add-1 to i's neighbor list 3) From the adjacency table obtained, create a look up in the form of a 2D array Cross: Box # 0 Box # 0 1 0 Neighbor List -1 Neighbor List -1 0,-1 3 o 5 6 A 2 3 2 3 7 5 6 5 6 7 7 Box # 0 1 2 Box # 0 1 2 3 Box # 0 1 2 3 4 Box # 0 1 2 3 4 S Neighbor List -1 0,-1 0, 1,-1 Neighbor List -1 0,-1 0,1,-1 0, 2, -1 Neighbor List -1 0,-1 0,1,-1 0,2,-1 1.2.-1 Neighbor List -1 0,-1 0,1,-1 0, 2, -1 1,2,-1 1,2,3,4,-1 O 0 0 1 2 3 2 3 2 3 1 2 3 S 5 6 5 6 6 5 6 7 7 7 7 Box # 0 1 2 3 4 S 6 Box # 0 1 2 3 4 S 6 7 Neighbor List -1 0.1.-1 0,2,-1 1,2,-1 1,2,3,4,-1 2, 3, 5, -1 Neighbor List -1 0,-1 0,1,-1 0,2,-1 1,2,-1 1,2,3,4,-1 2,3,5,-1 4, 5, 6,-1 {0, -1}, //box 1 {0, 1, -1}, //box 2 。 (0, 2,-1}, //box 3 {1, 2,-1}, //box 4 {1, 2, 3, 4, -1}, //box 5 {2, 3, 5, -1}, //box 6 {4, 5, 6, -1} //box 7 0 M 2 3 M 2 m 4 s 6 5 7 The Adjacency Table in C++ (Based on the Labeling Above) 115 columns because the largest neighbor list contains 5 numbers in our case int adj_table[8][5] = { //column size varies! {-1}, //box 0 7 Psuedo-Code for ok function bool okay(int cross[], int box) { static int adj_table[8][5] = {...}; do eight-queens style row-check here; if the test fails, return false //consecutive number check, notice that we only care to check the neighbors //of the current box, hence the need for the adjacency table i = 0; } neighbor_box = adj_table[box][i]; //this is the index of an adjacent box! while (neighbor_box != -1){ if (value at neighbor_box and cross[box] are consecutive) return false; move on to next neighbor box } return true; Project 2: Eight Numbers in a Cross Write a program which allocates the integers 1-8 to the squares in the figure above, subject to the restrictions that no two adjacent squares contain consecutive integers. By adjacent we mean vertically, horizontally, or diagonally. Please provide both recursive solution and backtrack solution. Submission detail: Two independent cpp files should be submitted. 50 pt-Backtrack solution 50 pt - Recursive solution 8 number Eight Number in a Cross In the solution to this problem, use the backtracking scheme that we covered in class. Write a program which allocates the integers 1-8 to the squares in the figure above, subject to the restrictions that no two adjacent squares contain consecutive integers. By adjacent we mean vertically, horizontally, or diagonally. Eight Number in a Cross By-Hand Algorithm to. Obtain Adjacency Table 1) Label cross boxes arbitrarily from 0 through 7. 2) for each box i=0., 1.... 7: for each adjacent box k (such that k <i): add k to i's neighbor list add-1 to i's neighbor list 3) From the adjacency table obtained, create a look up in the form of a 2D array Cross: Box # 0 Box # 0 1 0 Neighbor List -1 Neighbor List -1 0,-1 3 o 5 6 A 2 3 2 3 7 5 6 5 6 7 7 Box # 0 1 2 Box # 0 1 2 3 Box # 0 1 2 3 4 Box # 0 1 2 3 4 S Neighbor List -1 0,-1 0, 1,-1 Neighbor List -1 0,-1 0,1,-1 0, 2, -1 Neighbor List -1 0,-1 0,1,-1 0,2,-1 1.2.-1 Neighbor List -1 0,-1 0,1,-1 0, 2, -1 1,2,-1 1,2,3,4,-1 O 0 0 1 2 3 2 3 2 3 1 2 3 S 5 6 5 6 6 5 6 7 7 7 7 Box # 0 1 2 3 4 S 6 Box # 0 1 2 3 4 S 6 7 Neighbor List -1 0.1.-1 0,2,-1 1,2,-1 1,2,3,4,-1 2, 3, 5, -1 Neighbor List -1 0,-1 0,1,-1 0,2,-1 1,2,-1 1,2,3,4,-1 2,3,5,-1 4, 5, 6,-1 {0, -1}, //box 1 {0, 1, -1}, //box 2 。 (0, 2,-1}, //box 3 {1, 2,-1}, //box 4 {1, 2, 3, 4, -1}, //box 5 {2, 3, 5, -1}, //box 6 {4, 5, 6, -1} //box 7 0 M 2 3 M 2 m 4 s 6 5 7 The Adjacency Table in C++ (Based on the Labeling Above) 115 columns because the largest neighbor list contains 5 numbers in our case int adj_table[8][5] = { //column size varies! {-1}, //box 0 7 Psuedo-Code for ok function bool okay(int cross[], int box) { static int adj_table[8][5] = {...}; do eight-queens style row-check here; if the test fails, return false //consecutive number check, notice that we only care to check the neighbors //of the current box, hence the need for the adjacency table i = 0; } neighbor_box = adj_table[box][i]; //this is the index of an adjacent box! while (neighbor_box != -1){ if (value at neighbor_box and cross[box] are consecutive) return false; move on to next neighbor box } return true;
Expert Answer:
Related Book For
Fundamentals of Physics
ISBN: 978-0471758013
8th Extended edition
Authors: Jearl Walker, Halliday Resnick
Posted Date:
Students also viewed these accounting questions
-
A shelf holds 12 books so that no two adjacent books are chosen if there are 5 books?
-
In Figure two long straight wires (shown in cross section) carry currents i1 = 30.0 mA and i2 = 40.0 mA directly out of the page. They are equal distances from the origin, where they set up a...
-
Provide two examples of data files and program controls.
-
If the arch rib \(A B C D E\) in Figure \(\mathrm{P} 6.30\) is to be funicular for the dead loads shown at the top joints, establish the elevation of the lower chord joints at \(B\) and \(D\). 40...
-
What are the Nash equilibria if both Intel and AMD act simultaneously in the game in the Managerial Solution?
-
Estimate the slope of the tangent line to each curve at the given point (x, y). y 2- 2+ (2, 2) 2 A+++ X
-
Under the Single Audit Act, specific requirements include: a. Political activity. b. Federal financial reports. c. Eligibility. d. Administrative requirements. Choose the correct answer.
-
Gross Profit Method Zidek Corp. requires an estimate of the cost of goods lost by fire on March 9. Merchandise on hand on January 1 was $38,000. Purchases since January 1 were $92,000; freight-in,...
-
At the beginning of project raw material was purchased on $20,000 and then every year increases by 15% over 5 years. Other current assets will not change. What is change in working capital and...
-
Explain how personal selling can help solve the problem of information overload.
-
The skirt of piston (a) is used to withstand the pressure of gas in the cylinder (b) acts as a bearing for the side thrust of the connectingrod (c) is used to seal the cylinder in order to prevent...
-
What characteristics of an asset make it useful as a medium of exchange? As a store of value?
-
Discuss what is meant by upward influence and the various influence tactics categories associated with it.
-
Should financial markets be subject to more or less regulation if we are to avoid another financial crisis of the scale of that witnessed between 2007 and 2009? Justify your answer.
-
Why is deflation a potentially damaging phenomenon?
-
How does resilience promote motivational attributions?
-
If, if-else, and switch Statements Objective: Create an interactive Java program that reads in user input and outputs a message dependent on user input, demonstrating the student's understanding of...
-
If someone's Z-score for a variable was 0.67. Their score is a significant extreme score. Their score is not significant. O Their score is slightly above average. O Their score is an outlier.
-
Two uniform solid cylinders, each rotating about its central (longitudinal) axis at 235 rad/s, have the same mass of 1.25 kg but differ in radius. What is the rotational kinetic energy of (a) The...
-
What must be the ratio of the slit width to the wavelength for a single slit to have the first diffraction minimum at = 45.0o?
-
System A of three particles and system B of five particles are in insulated boxes like that in Figure. What is the least multiplicity W of (a) System A and (b) System B? What is the greatest...
-
For a non-ideal gas, fugacity (a) Is equal to pressure (c) Is not concerned with pressure at all (b) Is not equal to pressure (d) None of these.
-
The effect of temperature on fugacity can be represented by (a) \(\left(\frac{\partial \ln f}{\partial P} ight)_{T}=\frac{V T}{R}\) (b) \(\left(\frac{\partial \ln f}{\partial P} ight)_{T}=\frac{V...
-
A process is said to be uniform if there is (a) No change with time (b) No change with location over a particular region (c) Both(a) and (b) (d) Neither (a) nor (b).
Study smarter with the SolutionInn App