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.
-
(
mult-13?
) Return true if a number is a multiple of 13, false otherwise. -
(
tg
: Thinking Only) Thetotal-gap
functiontg
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. -
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))]))
- (
ced
) Count how many odd digits a number has. - (
c13
) How many pairs of consecutive digits are multiples of 13. The pairs of digits can overlap. Write examples and then write the function.