22a. Digits III

More practice problems using quotient and remainder to work through the digits of a number.
  1. (ism? : number -> boolean) Return true if a number is a multiple of 19 or a divisor of 5698296.

  2. (twentyish: number -> number) Take each non-zero digit in a number, divide 20 by that number, and add up the results.

     (twentyish 14) => 20/1 + 20/4 = 25
     (twentyish 145) => 20/1 + 20/4 + 20/5 = 29
    
    1. Write a sequence of three more related examples.
    2. Write the function.
  3. Without running the function, trace through the code below to show what happens with (mess 15), (mess 23) and (mess 41).

     (define (mess n)
       (cond [(< n 20) 5]
             [(= 3 (remainder n 5))
              (mess (- n (remainder n 7)))]
             [else (add1 (mess (- n 4)))]))
    
  1. (numimg: number -> image) Draw a different shape in the place of some of the digits of a number. The example below uses 0=circle, 1=square, 2=triangle, 3=star, and anything else is a yellow square. Use at least three shapes in your function.

     (numimg 12035532)
    

    Image of shapes corresponding to 12035532

    1. Draw a sequence of three related examples. (Might not go in Racket right away.)
    2. Write the function.
    3. Turn your examples into check-expects.
  2. (2dg: number -> number) Write down your number. Beginning at the right, where the decimal point would be, make two digit groups of its digits. Add up all of the two digit groups. Ignore any extra digits that do not fit in two digit groups.

     (check-expect (2dg 14258) 100) ;; 58 + 42 = 100
    
    1. Write a good sequence of examples building up to a six digit number.
    2. Write the function.
  3. (count-div3: number -> number) Count the number of digits in a number that are divisible by 3.

Last modified August 18, 2023: 2022-2023 End State (7352e87)