COMP 15
Programming Assignment 1:
Recognizing Palindromes

Assigned:
Monday Aug 30, 1998
Due:
Thursday Sep 9, 1998

"A man, a plan, a canoe, pasta, heros, rajahs, a coloratura, maps, snipe, percale, macaroni, a gag, a banana bag, a tan, a tag, a banana bag again (or a camel), a crepe, pins, Spam, a rut, a Rolo, cash, a jar, sore hats, a peon, a canal: Panama!" - T. Roosevelt

Problem Description

A word is a palindrome if it reads the same forwards and backwards. For example, the word
    level
is a palindrome. The idea of a palindrome can be extended to phrases or sentences if we ignore details like punctuation. Here are two familiar examples:
    Madam, I'm Adam 
    A man, a plan, a canal: Panama
We can recognize these more elaborate examples as palindromes by considering the text that is obtained by removing all spaces and punctuation marks and converting all letters to their lower-case form.
    Madam, I'm Adam                   ==>   madamimadam
    A man, a plan, a canal: Panama    ==>   amanaplanacanalpanama
If the "word" obtained from a phrase in this manner is a palindrome, then the phrase is a palindrome. The punctuation characters that should be ignored are comma (,), colon (:), and the apostrophe (').

For this programming assignment you should construct a Haskell script Prog1.hs that contains a function palindrome:

   -- palindrome s is True if sentence s is a palindrome and False otherwise
   palindrome :: String -> Bool

You may find it helpful to include the function strip in the script, to be used in the construction of function palindrome:

   -- strip s is the string obtained by removing all punctuation and 
   -- spaces from s and converting all characters of the alphabet 
   -- to their lower case form.
   strip :: String -> String

Test your program on the inputs at the top of the page and any others that you might be able to think of. For example:

  Prog1> palindrome "level"
  True

  Prog1> palindrome "Madam, I'm Adam"
  True

  Prog1> palindrome "Not a ton!"
  False


Submission Procedure

Programming Assignment #1 submission times are: Please save your program onto a floppy disk and bring it to this room during one of the submission periods. Several PC's running hugs and emacs will be available for you to demonstrate your program. Please arrive with your program ready for demonstration. You will also need a listing of your program. In case you can not obtain it elsewhere, you can print a listing in SN030 it at the time of submission.


$ Revised: Aug 29 1999 by prins@cs.unc.edu