22a. Helpers

Real introduction to helper functions in recursion.

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. largest-prime-factor: positive-integer(n) -> positive-integer. Find the largest 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".

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