Chapter 3 Test C
You may use the book, but not other reference materials, especially not Stack Overflow or any of your old homework.
-
The odd negative integers greater than -12 are [-11,-9,-7,-5,-3,-1]. Their product is 10395. The sign of this answer is +1 and the last two digits are 95, so
q1 (-12) = (1,95)
.A similar process with -14 produces a product of -135135, so the sign is -1 and the last two digits are 35.
Find the product of all odd negative integers greater than n. Create a tuple containing the sign (+1 or -1) and the last two digits (the tens and units digit). Example:
q1 (-12) = (1,95) q1 (-14) = (-1,35) q1 _ = (0,0) -- wrong
Test your code by printing
q1 (-2018)
Warning: The parentheses around the negative is important!
-
Create a list of lists called
vigenere
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. Put the ones digit first.base3 (1+2*3+1*9+0*27+1*81) == [1,2,1,0,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"