CS 458/558 - Problem Set 0

Assigned:Wednesday August 31
Deadline:Wednesday September 14, 11:59pm

This is a warmup exercise that really has little to do with decision making. Rather, it is an opportunity to begin to learn R and Python. You will implement the same functions in both languages.

Use the following files as templates:

  • hw0.R R version of the homework.
  • hw0.py Python version of the homework.

    You will submit both files, mutatis mutandis, using the zoo submit process.

    Function 1: palindrome

    A palindrome is a string or word or number or phrase that is the same backward as forward. Examples:
     radar
     Bob
     10101
     A man, a plan, a canal: Panama!
     Madam, I'm Adam
    

    Write a function palindrome which reads an ascii file comprising one word per line and returns all the palindromes. The default file is the standard UNIX online dictionary: /usr/share/dict/words There is another optional argument of a single letter, in which case the program returns only palindromes which start with that letter.

     >>> palindrome(letter = "b")
     B
     b
     Bab
     bab
     B/B
     BB
     bb
     BBB
     Beeb
     Bib
     bib
     Bob
     bob
     boob
     Bub
     bub
    

    Function 2: anagram

    Write a function anagram which reads an ascii file comprising one word per line and returns the largest set of words which are anagrams. The default file is the standard UNIX online dictionary: /usr/share/dict/words There is another optional argument which is a single word. In that case, the function returns all anagrams for that word Example output
     >>> anagram()
     ['alerts', 'alters', 'artels', 'estral', 'laster', 'lastre', 'rastle', 'ratels', 'relast', 'resalt', 'salter', 'slater', 'staler', 'stelar', 'talers']
     
     >>> anagram(target = 'male')
     ['alem', 'alme', 'amel', 'lame', 'leam', 'male', 'meal', 'mela']