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
.
Number Theory
-
smallest-factor
: positive-integer(n) -> positive-integer. Find the smallest divisor ofn
that is greater than 1. -
is-prime?
: positive-integer(n) -> boolean. True ifn
is prime, false otherwise. -
largest-prime-factor
: positive-integer(n) -> positive-integer. Find the largest prime factor ofn
.
String Practice
group-3
: string(word) -> string. Insert spaces after every three letters of word
. Example: (group-3 "pancake") => "pan cak e"
.