Chapter 3 Quiz 3 From 1

  1. Write a good (technically correct) type signatures. Use the most general typeclasses that you can. You must use typeclasses for full credit.

    1. f x = x*(x+1)
    2. g xs = [ x/7 | x <- xs ]
    3. h x = "You told me "++(show x)
    4. k (x,y) = y*x - 5
  2. 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"]
  1. 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
  1. (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 value 0+1*3+2*3^2 = 21. Write a function tbt to convert a number to base three.
   tbt 21 == [0,1,2]
  1. (You are forbidden from using read and show in this question.) The number reverse function, nr: Int -> Int reverses the order of the base 10 digits of a positive number. Write nr.
    nr 98103 == 30189
  1. 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
Last modified October 19, 2024: Revisions of quizzes. (5422276)