Assignment 2
Due: 11:00 AM on Friday, September 23, 2011
Question #1
A non-decreasing sequence of integers is any sequence of integers in which
each integer is greater than or equal to the integer coming before it in the sequence.
Write and document a Python script ndseq.py which takes as
a command-line argument a textfile and computes and prints the length of the
longest non-decreasing sequence of integers in that file.
Your script must work on datafiles
nd1.dat,
nd2.dat,
nd3.dat,
nd4.dat and
nd5.dat
to produce the output given in typescript-file
ndseq.script.
You may assume that all space/tab-separated strings in the given files
can be converted to valid integers and that all of these values between -1000000
and 1000000.
Question #2
Write and document a Python script tcomp2.py which takes as
command-line arguments a master textfile, a word-pair, and two or more comparison
textfiles and prints (1) the number of occurrences of the given word-pair in (not across)
the lines in the master
textfile and each of the comparison textfile and (2) the name of the comparison textfile
that is most similar to the master textfile relative to that word-pair, i.e., the
comparison textfile whose count for that word-pair is closest to the count for that
word-pair in the master textfile.
Your script must work on datafiles
tc1.dat,
tc2.dat, and
tc3.dat
to produce the output given in typescript-file
tcomp2.script.
You may assume that each textfile has at most one million words and that words in the
word-pair are different, i.e., occurences of word-pairs in the file cannot overlap.
Hints
You may find the answer scripts for Assignment #1 of use.
Submission
Please hand in printed copies of all of your Python script files.
You must also submit these files electronically using the
submit-assignment command.
Note that each script file must have the following comment
block at the top, where the X's are replaced with the appropriate
information, followed by a docstring briefly describing the program in that
script. For instance, my script for Question #1 of this assignment would
begin with the following comment block:
#########################################################
## CS 2500 (Fall 2011), Assignment #2, Question #1 ##
## Script File Name: ndseq.py ##
## Student Name: Todd Wareham ##
## Login Name: harold ##
## MUN #: 8008765 ##
#########################################################
You do not have to develop your code on our CS departmental systems.
However, as your code will be compiled and tested on our CS departmental
systems as part of the assignment marking process,
you should ensure that your code compiles and runs correctly on at
least one of these systems.
- September 14, 12:30pm
Errors in Questions #1 (missing file "nd5.dat") and Question #2 (incorrect
given data and output-script files) in Assignment #2 fixed.
- August 9, 4:50pm
Assignment #2 posted.
Created: August 9, 2011
Last Modified: September 14, 2011