22a. Digits II

Making useful examples. Reading code. Practice problems using quotient and remainder to work through the digits of a number.

After this worksheet you are supposed to know how to process a number digit by digit, or in groups of digits.

  1. (mult-13?) Return true if a number is a multiple of 13, false otherwise.

  2. (tg: Thinking Only) The total-gap function tg finds the total of the positive difference between adjacent digits of a number. That means you will look at each pair of neighboring digits, find their “positive differences”, and then add up those differences. You are just writing good examples that you will use to write that function.

  3. Trace out the following function in the examples when n is 7, 19, and 129.

(define (bogus n)
  (cond [(<= n 10)   0]
        [(<= n 100) 21]
        [else (+ (bogus (- n (remainder n 10)))
                 1
                 (remainder n 10))]))
  1. (ced) Count how many odd digits a number has.
  2. (c13) How many pairs of consecutive digits are multiples of 13. The pairs of digits can overlap. Write examples and then write the function.
Last modified August 18, 2023: 2022-2023 End State (7352e87)