This warm-up assignment is due on Wednesday, September 12.
(Per the automatic grace policy, you actually can turn it in as late
as Thursday midnight. However, there will be another more extensive
assignment by then, so it is best not to wait, unless you have an
emergency.)
Please see the tutoring
schedule for the schedule of tutoring hours. You may also send e-mail to
cs60help@cs.hmc.edu for
specific questions.
Before submitting this assignment, you will need to familiarize yourself with Unix, the operating system used on turing. You will also need to learn the basics of emacs, the text editor of choice. (If you have another editor that you prefer to use on turing, that is fine.) Finally, it may be worth spending some time learning to an e-mail program such as pine or elm. Documentation on Unix, emacs, and other items can be found on the CS 60 homepage under "Reference Links". Please spend some time reading this, and trying out Unix, emacs, and pine before embarking on the main part of the assignment. The grutors and CS staff in the terminal room will be happy to help you when you have questions.
You should also have read Chapters 1 and 2 in the course text before starting this assignment.
assign1.rex. This file must
be loadable into into the rex system without generating any errors, so make
sure you have comments around all the non-rex parts of your answers.
Whenever you are ready you can submit your file by running
cs60submit assign1.rex
(Make sure that assign1.rex is in the current directory when you
do this!) You will be prompted for theassignment number; answer with the number
1. Remember, you can submit the assignment as many times as you want. The graders
will grade only the last submission you make, so this is a great way to make
backups of your work as you go along.
thirty to be the result of representing
the number 30 using this representation. [It is very important that in
all assignments you use exactly the names specified for variables and
functions! Some assignments will use an automated grading process that
will give you no credit if you fail to follow directions.] Consider a computer application that colors 2-dimensional maps for publication purposes. A map consists of a set of countries (or other political regions). Assume that each country is a contiguous region. Any two countries either touch or do not. When the application colors a map, it cannot color two touching countries with the same color. The application always uses the smallest number of colors possible to color a map.
map_input and map_output
to be the corresponding list representations for the following example
(selected North African countries, from http://www.sas.upenn.edu/African_Studies/CIA_Maps/Africa_19850.gif)
Input:
Output:
The text explains that binary relations can be identified with sets of
ordered pairs; two elements x and y are said to be related
by this relation if the pair (x,y) is in the set. A relation
is reflexive if every element in the domain of interest is related
to itself; that is, if the pair (x,x) is in the relation for
every relevant x. A relation is symmetric if whenever (x,y)
is in the relation so is (y,x). Finally, a relation is said
to be transitive if whenever (x,y) and (y,z) are in
the relation, so is (x,z).
An equivalence relation is a binary relation that is reflexive, symmetric
and transitive. For example, given the finite set S = {1,2,3,4,5,6,7},
the relation on this set that relates two numbers in this set if they have
the same remainder when divided by three (also known as equivalence mod
3) is an equivalence relation. As discussed in the text, we can represent
relations on a finite set as a list of all the pairs that are related:
[[1,1], [1,4], [1,7],
[2,2], [2,5],
[3,3], [3,6],
[4,1], [4,4], [4,7],
[5,2], [5,5],
[6,3], [6,6],
[7,1], [7,4], [7,7]]
However, the properties of equivalence relations permit a more compact encoding.mod3 to be the result of representing
the above relation using your encoding.The text describes ways to represent directed graphs; a labeled directed graph is a directed graph where every arrow has a corresponding label. In such graphs we permit more than one arrow between two nodes (or from a node to itself) as long as the arrows have different labels. The same label may appear on several different arrows (as long as the arrows do not have both the same source node and target node).
graph1, graph2, etc.
to be implementations of the following labeled graph for each of your
representations. (Remember that you will need to represent the nodes using
strings such as "a" in your rex code.)