ICS 492 Ruby on Rails
Metropolitan State University
Spring 2008
Week 1 Programming Assignment
1. Install InstantRails at home
2. Write a program to
create a word histogram.
Inputs:
- The
name of a text document
Processing:
- Open
and read the text document
- Make
a list of all the unique words in the document
- Count
the number of occurrences of each word
- Count
the total number of words in the document
Outputs:
- Display
the words and their counts
- Display
the total number of words in the document
- (Optional)
Display the words and their counts in order from most frequent to least
frequent
- (Optional)
Display only the 20 most frequent words and their counts
Definition of a word:
- Any
set of alphabetic characters delimited by spaces or punctuation
(Hint: split on whitespace which
can be represented by the regular expression /\W/ )
- Words
are case insensitive. That is,
“Dog” == “dog”
- Blank
lines, spaces and punctuation are not words
An Easier Solution:
Just to get started, you can assume your file has one word
per line. But for your final solution,
you must handle files with punctuation and multiple words per line.
Due date:
- May
15, 2008 (preferred)
- May
29, 2008 (final deadline)
It is in your best interests to get each weekly assignment
working as you go. However, no late
penalties will be applied. All work must
be completed and demonstrated to the instructor by May 29. No exceptions.
Turn in:
- Demonstrate
your program to the instructor during lab.
- If
your program does not pass the instructor’s test data, you will be asked
to fix your program before it will be accepted.