CS 313 - Homework 10 - Problem collection
Due: Monday, 5/15, 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 12+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
to figure out how to do such things.
- You may use any language discussed in this course, except
the procedural languages (Pascal, C, and Python*).
That leaves Smalltalk, Ruby, Scheme, ML, and Prolog.
(*Note: If you really like Python, check out problem 12.)
- The language you use for each problem has to belong to a
different paradigm (OO, functional, logic). For example, if you
solve one problem using Scheme, you will have to use Smalltalk,
Ruby, or Prolog for the other problem (not Scheme or ML). If
you solve three problems, you need to use all three paradigms.
- I have rated the difficulty of the problems listed below on
a scale from 1 (not so hard) to 3 (hard). For full credit, the
sum of the difficulties for all problems you solve has to be at
least 4 (e.g., 1+3, or 2+2, or even 1+1+2). Note that the
rating of difficulty is my own (subjective) estimate - your own
rating may be different :)
- In case you can't solve any of the harder problems, you may
opt to solve easier (or fewer) problems for a grade penalty.
This will likely result in a higher grade than submitting a
program that doesn't work. If you achieve a sum of difficulties
of 3, the penalty is 15%; for a sum of 2 it is 30%.
- You are not allowed to consult books or the web for
solutions for these problems!
To submit your code, create a zip file containing all your programs.
code for each problem in a separate file with the proper
extension. For problem 12, include all solved problems in a single
file. For all problems, include sample output as comments in your
files. Also, please list any collaboration and help you received and
also list any souces you consulted.
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.
Upload your file (one submission per group) via the HW 10 submission page by midnight
of the last day of classes, Mond 5/15.
- 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
[[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], , [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).
- Write a program that, given interval [lo, hi],
prints the numbers as English words in alphabetical order.
For instance, for the interval [8, 15]
the output should be
You can use this web
page to check the spelling of numbers (use the American English
version, but omit the commas). You can also do it in a different language
if you wish. You may assume that 0 ≤ lo < hi ≤ 9999.
- 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
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. Careful, this
problem is trickier than it looks...
- 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.
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.
- Write a program to play Tic-Tac-Toe against the
user, using a text-based user interface
- Write a program to solve the 8-Queens problem, to place
8 queens on a chess board such that no queen attacks another.
- 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 ("English")
version with 33 spots (32 pegs and 1 hole) -- boards #4 and #6 in
this image. 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).
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.
- Write a program to solve Sudoku puzzles, 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.
- 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.)
- 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
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").
- 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.
- Python + Ruby special: Solve as many of the problems at Project Euler as you can, using
only Python and Ruby, using each language for half of the problems.
(If you solve an odd number of problems, i.e., 2N+1, then at least N
solutions need to be in Python and N in Ruby). 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
or Ruby, 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 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 1/3, and problems 30 and higher
count as difficulty 0.5. Please take a screen shot of your
project Euler account that shows which problems you have solved.
Submit your answers in three files, euler.py, euler.rb, and euler-screenshot.png.
- 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 ;).