CS 313 - Homework 10 - Problem collection

Due: Friday, 5/8, at midnight

This is the last programming assignment. You are encouraged to work on it in groups of two, but you can also work by yourself. Below is a list of 10+1 programming problems, of which you have to solve (at least) two, according to the following rules: Some problems will require language features not discussed in class. For example, to write a Tic-Tac-Toe player, you will need to ask the user for input. You will have to consult the on-line documentation or books from the library to figure out how to do such things

Hand in a printout of your code and of sample output (one per group). More than in previous assignments, in grading your solution, I will give special weight to good documentation and to good sample output that demonstrates thorough testing. As usual, on the first page of your printout, write your name, the names of the students with whom you collaborated, and how much time it took you.

The problems

  1. Write a program to test whether two polygons intersect. The polygons are not necessarily convex. Each of the two polygons is represented with a list of its points in clockwise order. For example, given the three polygons
          A = [[0 0] [2 1] [4 8] [4 0]]
          B = [[6 5] [6 2] [0 2] [0 5]]
          C = [[1 4] [2 4] [1 3]]
    
    the only two that don't intersect are A and C (you might want to draw a picture of the three polygons). Hint: to test whether a point is contained in a polygon, count the number of times a ray starting at the point intersects an edge of the polygon. If this number is odd, the point is inside.
    Difficulty: 1

  2. Write a program that takes a description of a directed graph as input, and reports whether the graph has cycles. The description of the graph should be a list of lists, where there is one sublist for each node in the graph. The first element in each sublist should be the name (or number) of the node, and the remaining elements should be the destinations of the edges leaving this node. For example, the list
          [[a, b], [b, c], [c, a]]
    
    describes a cyclic graph with three nodes a, b, c, and three edges (a, b), (b, c), and (c, d). The list
          [[1, 2, 4, 3], [2, 3, 4], [3], [4, 3]]
    
    describes an acyclic graph with four nodes 1, 2, 3, 4, and six edges (1, 2), (1, 4), (1, 3), (2, 3), (2, 4), and (4, 3).
    Difficulty: 1

  3. Write a program to solve the Missionaries and Cannibals problem. The Story:
    Three missionaries and three cannibals are traveling together through the jungle. Why are the cannibals traveling with the missionaries? Perhaps in the expectation of an easy meal. Their problem, there will be no easy meals unless they outnumber the missionaries.
    They arrive at a river. There is a boat. The boat can carry, at most, two people. Both the missionaries and cannibals can operate the boat. Can the missionaries devise a series of boat trips that will transport the entire party across the river and where, on either bank, the missionaries will not be outnumbered and become an easy meal?
    Your program should compute and output a sequence of boat trips that solves the problem.
    Difficulty: 2

  4. Write a program to play Tic-Tac-Toe against the user, using a text-based user interface
    Difficulty: 2

  5. Write a program that solves the Peg Solitaire game (often found in Friendly's restaurant), either the triangular version with 15 spots (14 pegs and 1 hole), or the cross-shaped version with 33 spots (32 pegs and 1 hole). The goal of the game is to remove all pegs except one, by jumping over each peg with another peg (which removes the peg that was jumped over). If you don't know the game, check out some versions on the web: cross and triangle. Note: you don't have to program a graphical user interface (or any user interface, for that matter). All your program should do is compute and then print out a solution for the puzzle.
    Difficulty: 2

  6. Write a program to solve Sudokus, either 6x6 or 9x9. Come up with a way to encode puzzles, e.g., a list of 36 or 81 numbers, with blanks represented by 0. You may search the web for downloadable puzzles, but not for puzzle solvers of course.
    Difficulty: 3

  7. Write a version of the Eliza program to simulate a conversation with a psychiatrist. (Type "ESC-x doctor" in xemacs for an example of such a program.)
    Difficulty: 3

  8. Write a problem to solve the 8-Puzzle (also known as sliding-blocks puzzle). Given an initial configuration, your program should output the moves necessary to solve the puzzle. For example, the puzzle
              1   3
              4 2 6
              7 5 8
    
    can be solved by moving 2 up, 5 up, and 8 left:
    	  1   3        1 2 3        1 2 3        1 2 3
    	  4 2 6   ->   4   6   ->   4 5 6   ->   4 5 6
    	  7 5 8        7 5 8        7   8        7 8  
    
    Your program should take the initial configuration as input (e.g., "1 0 3 4 2 6 7 5 8", where 0 represents the hole), and output the moves to solve the puzzle (e.g., "2, 5, 8").
    Difficulty: 3

  9. Write a program to solve the Pentomino puzzle. There are 12 puzzle pieces, similar to the Tetris pieces, but built from 5 unit squares each (not 4). Your program should find solutions for the 6x10, 5x12, 4x15, and 3x20 rectangles. See also this web page.
    Difficulty: 3

  10. Python special: Solve as many of the problems at Project Euler as you can, using only Python. You'll need to create an account so you can verify whether your solutions are correct. Once you submit a correct answer, you'll be able to see other people's solutions - feel free to check them out, especially the ones in Python, but you may not modify your own solution at this point. Keep your programs as short as possible without sacrificing readability. For the purpose of this homework, all your Python solutions to the Project Euler problems only count as a single HW problem solved, in a separate paradigm, i.e. they don't restrict what languages you may use for the other problem(s). The total difficulty is computed as follows: problems 1-29 count as difficulty 0.5, and problems 30 and higher count as difficulty 1.

  11. Wildcard - If you have some other really cool program you want to write, that's great! Just discuss it with me first, and we'll also need to agree on how many points it's worth ;).