15-112 Spring 2015 Homework 9
Due Sunday, 29-Mar, at 10pm

Read these instructions first!

Hw9a: COLLABORATIVE
  1. CA-led code reviews [manually graded by participation] [nothing to submit] [5 pts] (See above for details.)
  2. from f13-hw9: study the recursion notes (this semester's, of course) [in triple-quotes] [manually graded] [10 pts]
  3. from f11-hw5: Reasoning About (Recursive) Code [in triple-quotes] [manually graded] [15 pts; 3 pts each]
  4. from f14-hw9: bubblesort [manually graded] [10 pts]
  5. from f11-hw5: fractalMickeyMouse (and mickeyFace) [manually graded] [10 pts]


Hw9b: SOLO
  1. from f11-hw5: flatten [manually graded] [10 pts]
  2. from f11-hw5: findLargestFile [manually graded] [10 pts]
  3. from f13-hw9: solveABC [manually graded] [30 pts]


Hw9 bonus: SOLO Bonus
  1. from f14-hw9: bonusTwoStackHanoi [manually graded] [2 pts]
  2. from f14-hw9: bonusPythagorasTree [manually graded] [2 pts]

  3. bonusPegSolitaire [manually graded] [5 pts]

    First, read up on peg solitaire here, and then read this entire writeup carefully. Then, write a peg solitaire solver using backtracking. The boards will be given to the function as a string of periods, O's, and spaces, which represent holes, pegs, and invalid spaces respectively (see examples below). The result should be returned as a list of moves to be made in the form (fromRow, fromCol, toRow, toCol), which indicates which piece to pick up (the from piece) and where it goes (the to piece). Your function must give the answer in a reasonable amount of time, which is defined as 10 seconds.

    Note that this problem is actually pretty difficult to do. This is because there are a lot of possible moves one can make at some stages in the puzzle (whereas in nQueens for example there are always only n possible moves). As such, we will grade on a rolling scale as such (examples of each case below).

    1pt boards with 10 pegs
    1pt boards with 14 pegs
    1pt boards with 16 pegs
    2pts boards with 32 pegs

    Your basic backtracking will eventually get the correct answer for all situations, but it'd probably take many many years to get the solution to the 32 peg board. As such, you will have to be a bit smarter to solve the higher peg boards, and maybe even need more advanced AI techniques to get the 32 peg board.

    Here are some boards to play with.
    board10 = """\
      ...  
      .O.  
    ..OO.O.
    .O...O.
    ..O.O..
      O.O  
      ...  
    """
    board14 = """\
      ...  
      OO.  
    ..O.OO.
    OO..OO.
    .OOO..O
      .O.  
      ...  
    """
    board16 = """\
      ...  
      OO.  
    ..OO...
    ..OO.OO
    OOO..OO
      OO.  
      .O.  
    """
    board32 = """\
      OOO  
      OOO  
    OOOOOOO
    OOO.OOO
    OOOOOOO
      OOO  
      OOO  
    """