Compsci 101, Fall 2014, Lab 10

Part 1: Regular Expressions

In answering questions about regular expressions you should provide both the answer, and the regular expression you used to answer the question. For example.

Question: How many words end in the letter 'a'.

Answer: There are 898 such words, the regular expression is a$, the first word is ababa and the last word is zomba.

You can use more than one regular expression to answer the questions. You can do calculations, record intermediate results, and so on. Be sure to report carefully the methods you used to arrive at your answer as well as the answer itself.

  1. How many five letter words are there that end with the letter 'd'?
    
    
    
    
    
    
    
    
    
  2. The regular expression [aeiou]$ indicates there are 6988 words that end in a vowel. How many words are there that start and end with a vowel?
    
    
    
    
    
    
    
    
  3. How many words are there that start and end with the same vowel --- words like amoeba?
    
    
    
    
    
    
    
    
    
    
  4. The words obsequious and pharmacopoeia each contain four vowels in a row. How many words are there that contain four consecutive vowels?
      
    
    
    
    
    
    
    
    
    
  5. The word maintaining contains the two letter sequence "in" repeated three times --- in genomics this could be called a triple-repeat. How many words are there that contain the two letter sequence "in" repeated three times (letters can appear between the "in" repeats)?
    
    
    
    
    
    
    
    
    
    
    
  6. The regular expression ((.).\2).*\1 matches the 12 words below (and only these words). Explain why these words match, how the regular expression works. Note that the expression (.) is the second tagged expression since the first left parenthesis begins the first tagged expression -- you count tagged expressions by the order in which the left-parenthesis appears in reading left-to-right.

    amalgamate
    amalgamated
    amalgamates
    amalgamatating
    amalgamatation
    assesses
    dereference
    monotonous
    monotonously
    monotonousness
    possesses
    sensitivities
    

  7. The regular expression ((.).\2){3} matches the two words below (and only these two words). Explain why these words match, i.e., how the regular expression works.
    agamemnon
    precipitateness
    
    
    
    
    
    
    
    

AuntUncle Questions

Consider the following example:

parents = ["JOE MARY FRANK", "BOB JANE MARTHA", "FRANK MARTHA ROB", "BOB AMANDA TROY"]
target = "ROB"
Returns: ["TROY"]
  1. Explain how to get the names of all the children in the list parents.
      
      
      
      
      
      
      
      
      
      

  2. Given any name, the target or the name of another child, explain how to get the names of his/her parents.
      
      
      
      
      
      
      
      
      
      

  3. Write the function, get_rents, that returns a list of the names of the parents, either 0 or 2, of the given name.
      
      
      
      
      
      
      
      
      
      

  4. Write a loop that calls the function get_rents to get all the grandparents of the target name (think about what needs to be initialized before the loop is started as well). With which kind of collection (list, set, or dictionary) would it make the most sense to hold the grandparents?
      
      
      
      
      
      
      
      
      
      

  5. Write a loop that uses the function get_rents and the collection of grandparents to find all the grandparent's children --- these are the aunts and uncles of the target name.
      
      
      
      
      
      
      
      
      
      

  6. Look at the other examples on the APT page, are there any other special cases you need to consider in determining the final answer?