Ch 03 Test 2022-10b

Based on the 2019-2020 CCML Algebra 1 Contest number 1 and Coding Bat problems.

The restrictions on the sizes of the numbers are intended to allow you to use the same technique for your examples and your function solution.

Test code is in a skeleton.

  1. Determine the number of perfect squares between 100 and 10,000 excluding the endpoints.

    Write a function cpsq that determine the number of perfect squares between m and n (exclusive) for any $m,n \le 10,000$.

  2. An arithmetic sequence is an ordered list of numbers that increase by a constant amount. For the arithmetic sequence 2, 9, 16, etc.:

    1. The first term is 2. Determine the 259th term.
    2. How many multiples of 5 appear in this sequence on or before the 259th term?
    3. Write a function carith n that returns the number of multiples of 5 that appear in this sequence on or before term n.
  3. The number 217 has the property that the number built by dropping its one digit (21) is divisible by the number’s ones digit (7). How many positive three-digit numbers have this property? Put this in a variable q3.

  4. Determine the number of ways that four positive integers can be multiplied to give a result of 50.

    Right now you only know enough Haskell to solve this problem when “order matters”, so $1\cdot 1 \cdot 1 \cdot 50$ would be counted differently than $50\cdot 1\cdot 1 \cdot 1$. This makes the solution slow.

    Make a function called numways that takes in a positive number $k \le 50$ and puts out the number of ways that four positive integers can be multiplied to get $k$.

  5. Estimate $$\sqrt{12 + \sqrt{12 + \sqrt{12 + \ldots}}}$$ by writing a function s12n that takes in an integer n and puts out a float which is the pattern above but stopped after n repetitions. For example, s12n 1 is $\sqrt{12}$ and s12n 2 is $3.9324422 \approx \sqrt{12 + \sqrt{12}}$.

     s12n :: Int -> Double
    
  6. (sum28) Given a list of int, return true if the sum of all of the 2s in the list is 8. The number 22 does not count as any 2s. Only the number 2 counts.

  7. (has22) Given a list of int, return true if it contains a 2 next to a 2 somewhere.