From: Ramakrishnan Muthukrishnan Date: Fri, 26 Nov 2010 12:38:07 +0000 (+0530) Subject: solution to 2.61 and 2.62 X-Git-Url: https://git.rkrishnan.org/?a=commitdiff_plain;h=95b2ccf229800dc12a8cb9830fc8986509211ff6;p=sicp.git solution to 2.61 and 2.62 --- diff --git a/src/sicp/ex2_61.rkt b/src/sicp/ex2_61.rkt new file mode 100644 index 0000000..a443206 --- /dev/null +++ b/src/sicp/ex2_61.rkt @@ -0,0 +1,7 @@ +#lang racket + +(define (adjoin-set x set) + (cond ((null? set) (cons x set)) + ((= x (car set)) set) + ((< x (car set)) (cons x set)) + ((> x (car set)) (cons (car set) (adjoin-set x (cdr set)))))) \ No newline at end of file diff --git a/src/sicp/ex2_62.rkt b/src/sicp/ex2_62.rkt new file mode 100644 index 0000000..47fb870 --- /dev/null +++ b/src/sicp/ex2_62.rkt @@ -0,0 +1,8 @@ +#lang racket + +(define (union-set set1 set2) + (cond ((null? set1) set2) + ((null? set2) set1) + ((= (car set1) (car set2)) (cons (car set1) (union-set (cdr set1) (cdr set2)))) + ((< (car set1) (car set2)) (cons (car set1) (union-set (cdr set1) set2))) + ((> (car set1) (car set2)) (cons (car set2) (union-set set1 (cdr set2)))))) \ No newline at end of file