#lang racket ; Returns the result of raising base to the (non-negative) power exp. (define (pow base exp) (if (< exp 1) 1 (* base (pow base (- exp 1))))) ; Returns n!. (define (factorial n) (if (<= n 1) 1 (* n (factorial (- n 1))))) ; Returns the nth number in the Fibonacci series (0-indexed). (define (fib n) (if (<= n 1) 1 (+ (fib (- n 1)) (fib (- n 2))))) ; Returns #t if n is prime and #f otherwise. ; The first function shown is a helper function. ; This is not a fancy solution (such as the sieve of Eratosthenes) ; just a naive solution that checks if n is divisible by any ; integer in the range [2,n-1]. (define (prime?-help candidate divisor) (or (>= divisor candidate) ; divisor is at least candidate (and (not (= 0 (modulo candidate divisor))) ; candidate is not divisible by divisor (prime?-help candidate (+ divisor 1))))) (define (prime? n) (and (>= n 2) (prime?-help n 2)))