diff options
| author | Mike Vink <mike1994vink@gmail.com> | 2023-03-24 23:01:25 +0100 |
|---|---|---|
| committer | Mike Vink <mike1994vink@gmail.com> | 2023-03-24 23:01:25 +0100 |
| commit | ac1bf1b75868c873037f742b727e79ee5a97bae2 (patch) | |
| tree | ee160b8cb5b69e1ce9f7e5c8869b8ff24022a945 /coding-exercises/2/62.rkt | |
| parent | 16582f2c4094249f15d9ab37c1b49beafe542103 (diff) | |
progress
Diffstat (limited to 'coding-exercises/2/62.rkt')
| -rw-r--r-- | coding-exercises/2/62.rkt | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/coding-exercises/2/62.rkt b/coding-exercises/2/62.rkt new file mode 100644 index 0000000..705dcbd --- /dev/null +++ b/coding-exercises/2/62.rkt @@ -0,0 +1,15 @@ +#lang racket + +;; In each branch of the problem we either terminate the process or we reduce the problem to a subproblem with set - (car set) +(define (union-set set1 set2) + (cond ((and (null? set1) (null? set2)) '()) + ((null? set1) (cons (car set2) (union-set set1 (cdr set2)))) + ((null? set2) (cons (car set1) (union-set (cdr set1) set2))) + ((= (car set1) (car set2)) (cons (car set2) (union-set (cdr set1) (cdr set2)))) + ((> (car set1) (car set2)) (cons (car set2) (union-set set1 (cdr set2)))) + ((< (car set1) (car set2)) (cons (car set1) (union-set (cdr set1) set2))))) + +(define test-list (list 1 2)) +(define test-list2 (list 4 5 6 7)) +(union-set test-list test-list2) + |
