Am hoping to prevail upon a fellow Schemer for help debugging my solution to one of the final HtDP exercises. So close, yet so far!<br><br>The exercise adapts the checking-queens algorithm from Chapter 28 to state variables. It asks the student to do two things: 1) design two new functions, place-queen and unplace-queen, which serve to "set!" the chessboard as the algorithm backtracks into a solution, and; 2) implement those functions into a new version of 'placement.'<br>
<br>Here's a link:<br><br><a href="http://www.htdp.org/2003-09-26/Book/curriculum-Z-H-53.html#node_sec_43.3">http://www.htdp.org/2003-09-26/Book/curriculum-Z-H-53.html#node_sec_43.3</a><br><br>I've done all that, but my solution fails in a very strange way. Specifically, it generates the correct solution to for all boards up to 5 x 5:<br>
<br>;(check-expect (placement 1) (vector (vector true))) ;; passes<br>;(check-expect (placement 2) false) ;; passes<br>;(check-expect (placement 3) false) ;; passes<br>;(check-expect (placement 4) (vector (vector false false true false) (vector true false false false) (vector false false false true) (vector false true false false))) ;; passes<br>
;<br>;(check-expect (placement 5) (vector ;; passes<br>; (vector false false true false false)<br>; (vector true false false false false)<br>; (vector false false false true false)<br>
; (vector false true false false false) <br>; (vector false false false false true)))<br><br>On a 6 x 6 board, things start to get weird --<br><br>;(check-expect (placement 6) (vector ;; fails<br>
; (vector false false false true false false)<br>; (vector true false false false false false)<br>; (vector false false false false true false)<br>
; (vector false true false false false false)<br>; (vector false false false false false true)<br>; (vector false false true false false false))) <br>
<br>Here's what I get instead ---<br><br>(vector<br> (vector false false false true false false)<br> (vector true false false false false false)<br> (vector false false false false true false)<br> (vector false true false false false false)<br>
(vector false false false false true true)<br> (vector false false true false false false))<br><br>Compared to the correct solution, this result is off by one vector value, or "queen-position": "true" in 5th column, 5th row. That should be false -- the queen in column 6 should have "flipped" it after being placed. <br>
<br>I tested extensively the place and unplace functions, and they seem to work fine. Looking for patterns, I found that if you trace the trajectories of the queens positioned in <b>only</b> vector-column-indexes
0-3, the resulting board is exactly the one I'm left with. As if the queens in vector-column-indexes 4 and 5 haven't
been placed, even though the queen positions selected in columns 0-3 are
made <i>as though</i> they had! <br><br>Needless to say, things get progressively worse as the board dimension inputs get larger.<br><br>All my efforts to debug have been fruitless. I've sat with the Stepper literally for hours trying to trace the origins of this result, but to no avail. I don't understand how I could get the correct solution for 5, but have it blow up at 6, get worse at 7, etc. I also don't understand why the backtracking strategy which succeeded in all cases in Chapter 28 is not working here. I know there are subtle differences, especially in the base case, but it seems the backtracking approach which worked in the first should translate to the second. It's making me a little crazy. <br>
<br>I've posted two public ss files to Google docs for anyone who wants to take a look --<br><br>"placement-with-local" which is available here --<br><br> <a href="https://docs.google.com/leaf?id=0B_ZKElmhzsp-YzY2YzgxOTctYWFjOC00MDUwLWFlMTctYWMwNjk5MzE2MTgy&sort=name&layout=list&num=50">https://docs.google.com/leaf?id=0B_ZKElmhzsp-YzY2YzgxOTctYWFjOC00MDUwLWFlMTctYWMwNjk5MzE2MTgy&sort=name&layout=list&num=50</a><br>
<br>and "TestingFunctions" available here -- <br><br><a href="https://docs.google.com/leaf?id=0B_ZKElmhzsp-NDZiZWJiNzgtNjJhZC00NGRjLTlmNjAtNDE3ZTMwYzY4MWJl&sort=name&layout=list&num=50">https://docs.google.com/leaf?id=0B_ZKElmhzsp-NDZiZWJiNzgtNjJhZC00NGRjLTlmNjAtNDE3ZTMwYzY4MWJl&sort=name&layout=list&num=50</a><br>
<br>Placement-with-local contains the complete algorithm, while TestingFunctions contains all my tests for the auxiliary functions. Data definitions, written arguments for the algorithm (and a second alternative), function contracts, purpose statements, etc. are all included. <br>
<br>This is a function with a lot of moving parts, so anyone who dives into with me to try and help would be doing me an enormous favor. The only thing I can offer in return is lots of gratitude.... and maybe my grandmother's not-really-secret-but-totally-yummie recipe for Spanish "tortilla patata." <br>
<br>As always, any and all suggestions are welcome and appreciated.<br><br>Many thanks!<br><br>Dave Yrueta<br><br><br><br><br><br><br><br><br><br>