Chapter 3 Quiz 3 From 1
-
Write a good (technically correct) type signatures. Use the most general typeclasses that you can. You must use typeclasses for full credit.
f x = x*(x+1)
g xs = [ x/7 | x <- xs ]
h x = "You told me "++(show x)
k (x,y) = y*x - 5
-
Write a function to extract an integer from one string and output a list containing the second string repeated that many times.
prob2 "5" "dog" == ["dog","dog","dog","dog","dog"]
- Given two strings containing floating point numbers, return the sum of those numbers. (It is OK if your program might be off by 0.00001; don’t worry about making the numbers exact.)
prob3 "3.14" "2.81" == 5.95
- (
tbt
) Base 3 numbers are like binary numbers, but using 3 in the place of 2 everywhere. Example: we write the base three number 210 as[0,1,2]
and it has the value0+1*3+2*3^2 = 21
. Write a functiontbt
to convert a number to base three.
tbt 21 == [0,1,2]
- (You are forbidden from using
read
andshow
in this question.) The number reverse function,nr: Int -> Int
reverses the order of the base 10 digits of a positive number. Writenr
.
nr 98103 == 30189
- The root mean square of a list of numbers is the square root of the average of the squares of the numbers. Write a function to find the RMS of a list of floating point numbers.
-- results are approximate
prob4 [1, 10, 100] == 58.0259
prob4 [3.14, 2.81] == 2.979