#lang racket (module+ test (require rackunit)) (define (add a b) (+ a b)) (module+ test (check-equal? (add 1 2) 3) (check-equal? (add 4 5) 9)) (define (sub a b) (- a b)) (module+ test (check-equal? (sub 4 3) 1)) (define (one? n) (= 1 n)) (define (my-even? n) (cond [(negative? n) (my-even? (- n))] [(zero? n) #t] [(one? n) #f] [else (my-even? (- n 2))])) (module+ test (check-equal? (my-even? -3) #f) (check-equal? (my-even? 13) #f) (check-equal? (my-even? 32) #t)) (define (copy-str n str) (cond [(zero? n) ""] [else (string-append str (copy-str (sub1 n) str))])) (module+ test (check-equal? (copy-str 3 "abc") "abcabcabc")) (define (copy-str-tr n str [acc ""]) (cond [(zero? n) acc] [else (copy-str-tr (sub1 n) str (string-append str acc))])) (module+ test (check-equal? (copy-str-tr 3 "abc") "abcabcabc")) (define (char+1 c) (integer->char (add1 (char->integer c)))) (define (char-1 c) (integer->char (sub1 (char->integer c)))) (define (consecutive-chars fst lst [acc ""]) (cond [(char=? fst lst) (string-append acc (string fst))] [(char? fst lst) (consecutive-chars (char-1 fst) lst (string-append acc (string fst)))])) (module+ test (check-equal? (consecutive-chars #\A #\D) "ABCD") (check-equal? (consecutive-chars #\z #\u) "zyxwvu"))