CIS 210 '12 Fall Portfolio


These are the projects that I have done thus far in CIS 210:

1.  Pronounceable Pins alphacode.py


Too many PINs

We have to remember too many numbers: credit card PINs, student ID number, codes to open doors, and on and on. We're warned that we should remember these numbers instead of writing them down, but really the human brain is not well-suited to remembering a lot of meaningless numbers. I'll admit: I write them down. But could I remember more?
People aren't any better at remembering random sequences of letters than remembering random sequences of digits. However, we are much better at remembering sounds we can pronounce. The word “fesi” doesn't mean anything to me, but it's easier to remember than the number 2354 or the harder-to-pronounce word “iksf”. It turns out to be pretty easy to convert numbers like 2354 into pronounceable nonsense words like “fesi”
To create words that are easy to pronounce, we can build them out of consonant-vowel pairs like “ka” or “te”. As it turns out, if we omit ‘x’ and treat ‘y’ as a consonant, the English alphabet has 20 consonants (bcdfghjklmnpqrstvwyz) and 5 vowels (aeiou). 20×5=10×10=100, so one consonant and a vowel (20×5 combinations) is just enough to represent a pair of decimal digits (10×10 combinations).
To convert a number (like my office phone number, 346-4140) into an pronounceable string, we'll need to divide it into two-digit chunks.

We're dividing it up in base 10; the underlying representation in base 2 is not relevant to us in this program. To get the last two (low order) digits in base 10, we can take the remainder when divided by 100, using the ‘%’ operator. To get the rest of the digits, we'll use integer division ‘//’, because we want an integer result (34641, not 34641.40).

Now we want to convert those last two decimal digits, 40, into letters. We have 20 consonants and 5 vowels. Suppose we divide a number between 0 and 99 by 5. The quotient will be a number in the range 0..19, and the remainder will be in the range 0..4:

Just right for picking one of 20 consonants and one of 5 vowels!

If I do this again for the next two digits (41), and the next (46), and then the highest digit (3, treated as 03), my office phone number can be converted to the word “bomelela”. It has a nice ring to it.

2. Anagram Solver jumbler.py


***The file dict.txt will be needed!***


This program will read two strings from the command line. The first is a scrambled word (e.g., “hinttree”). The second is the name of a file containing a list of words, which will serve as a dictionary. It will check the scrambled word against every word in the word list. If the scrambled word can be rearranged to match the dictonary word, the dictionary word will be printed. After scanning the whole word list, the program prints the number of matches and the number of words in the list. For example:

$ python3 jumbler.py trsesi dict.txt
resist
sister
2 matches from 41238 words

3. Days Between Dates days_till.py

Calculates the number of days between two dates (that are less than ONE year apart). 
Notes: February 29 is a valid date in leap years but not in other years. It is always valid to give February 29 as an ending date. If the ending year is not a leap year, we treat Feb 29 as equivalent to March 1.
Usually, a year is a leap year if it is divisible by four, but the rules are a little more complicated:
Divisible by 4Divisible by 100Divisible by 400Leap year?
NoNoNoNo
YesNoNoYes
YesYesNoNo
YesYesYesYes
Note that leap years are important not only in determining whether an input date is valid, but also in determining the number of days between two dates.

4. Flooding the Cavern cavern.py


***The files graphics.py, grid.py, and cave.txt  will be needed***


Cave descriptions look like this:

cave 10 10 
hwall 0 0 10
vwall 0 0 10
hwall 9 0 10
vwall 0 9 10
vwall 0 6 7
vwall 0 4 3
hwall 6 5 4
vwall 4 4 5
 
The commands above describe a cavern with 10 rows of 10 cells, a horizontal wall from row 0, column 0 extending 10 cells to the right, a vertical wall from row 0, column 0 extending 10 cells down, and so on (with rows ordered from 0 at the top to 9 at the bottom, and columns ordered from zero at the left to 9 at the right). Walls are made of stone, and any part of the cavern that is not stone is initially filled with air. The grid.py module provided displays this cavern this way:

The program will fill each chamber of the cavern with water. The water color is changed each time a new chamber is discovered, so after scanning the entire cavern it will look like this:

The input and output in the command or terminal window will look like this:

$ python3 cavern.py cave.txt
3 chambers in cavern
Click mouse in cavern display to close






  

No comments:

Post a Comment