22a. Helpers

Warmup

Write a function count-div: number(k) number(n) -> number that gives 1 if k divides n and 0 otherwise.

Opener

count-divisors: positive-integer(n) -> positive-integer. Count how many integers 1,2,…,n divide the number n.

Count-divisors solution.

Number Theory

  1. smallest-factor: positive-integer(n) -> positive-integer. Find the smallest divisor of n that is greater than 1.

  2. is-prime?: positive-integer(n) -> boolean. True if n is prime, false otherwise.

  3. smallest-prime-factor: positive-integer(n) -> positive-integer. Find the smallest prime factor of n.

String Practice

group-3: string(word) -> string. Insert spaces after every three letters of word. Example: (group-3 "pancake") => "pan cak e".