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.
-
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)
-
Create a list of lists to represent the inside of this Vigènere cipher table.
-
(
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]
-
(
inCirc
) Given an integerw
, create a list of all integersx
that have the property that the point(x,-x)
(meaning $y$ is the opposite of $x$) inside the circle of radius2*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 usefromIntegral
.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$.
-
(
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
-
(
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"