Chapter 3 Test 2019-10

You may use the book, but not other reference materials, especially not Stack Overflow or any of your old homework.

  1. Find the product of all odd negative integers greater than -2017. Create a tuple called answer1 containing the sign (+1 or -1) and the last two digits (the tens and units digit). Example:

     answer1 = (-1, 23)
    
  2. Create a list of lists to represent the inside of this Vigènere cipher table.

  3. (base3) Write a function to convert a number to a list representing the number in base 3.

     base3 (81+9+2*3+1) == [1,0,1,2,1]
    
  4. (inCirc) Given an integer w, create a list of all integers x that have the property that the point (x,-x) (meaning $y$ is the opposite of $x$) inside the circle of radius 2*w centered at (w,w). This means you are looking for integer coordinate points on the line $y=-x$ that are within distance $2*w$ of the point $(w,w)$.

    Haskell will prefer that you call all of the points involved Double. The other choice is to write your own distance function and use fromIntegral.

     inCirc :: Double -> [Double]
    

    You can use your own distance function or this one:

     dist :: (Double,Double) -> (Double,Double) -> Double
     dist (x0,y0) (x,y) = sqrt $ (x-x0)^2 + (y-y0)^2
    

    Here is an image showing the situation where $w=4$ and there are 9 integer coordinate points that are distance $d \le 8$ from $(4,4)$ and on the line $y=-x$.

  5. (vig) You can encode messages using the table from question 2. Write a single letter encoder by using the letter from the message to choose the row and the letter from the key to choose the column:

     vig :: Char -> Char -> Char
     vig msg key = undefined
     checkit = (vig 'C' 'X' == 'Z') -- should be True
    
  6. (vigen) Enhance your single letter encoder from the previous question to encode messages. Take in two strings: the message and a key, and match up corresponding letters. (Repeat the key as necessary.)

    An example from Wikipedia using the secret key “LEMON”.

     vigen :: String -> String -> String
     vigen "ATTACKATDAWN" "LEMON" == "LXFOPVEFRNHR"
    
Last modified August 25, 2021: ap-cs 2019-2020 (4d1c12c)