Project #1- SetFun
(50 points)
CIS447
Due: Check Upcoming page.
Define the following functions.
Hand in results of run on function arguments as specified below.
1. setu
Input:
set1, set2 (two sets with no duplication of elements)
Returns:
Union of set1 and set2.
2. setdf
Input: set1, set2
Returns:
Set difference of set1 and set2.
3. setint
Input:
set1, set2
Returns:
Intersection of set1 and set2.
4. clean
Input:
lst (a list, containing no sublists)
Returns:
that same list with on duplication of elements
5. countatoms
Input:
lst (a list)
Returns: the number of atomic elements found in lst
and all its
sublists.
6. flatten
Input:
lst (a list)
Returns:
a list of the atomic elements of lst and all its sublists.
E.g.: (flatten '(a (b c) d)) ==> (a
b c d)
7. countuniqueatoms
Input:
lst (a list)
Returns: the number of unique atomic elements found in lst
and all its
sublists.
8. subset
Input:
lst1, lst2 (contain no sublists nor duplicate elements)
Returns:
t if
lst1 is a subset of lst2.
9. sameset
Input:
lst1, lst2 (contain no sublists, but may contain duplicate elements)
Returns:
t if
lst1 contains the same set of elements as lst2.
Bonus (5 points):
10. fclean
Input:
lst (a list which may contain sublists)
Returns:
that same list with no duplication of elements
Test Data:
Below
are the values to use in providing the test runs of your functions
for
Project #1.
(setf
t1 '(a b c d))
(setf
t2 '(a b e f))
(setf
t3 '(e f g h))
(setf
t4 '(c d e f))
(setf
t5 '(a b a b c a d b))
(setf
t6 '(a b b a c c d a d))
(setf
t7 '(b a b b a c d d a))
(setf
t8 '(b c a e a b c a a))
(setf
t9 '(a b a b d a b b d))
(setf
t10 '(a (b c) d))
(setf
t11 '(a (b (c (d) () e) f) g h))
(setf
t12 '(((()))))
(setf
t13 '((a) (b c (d e)(f g (h) i) j k) (l) (m) n))
(setf
t14 '(()()()()))
(setf
t15 '(((()))(())()))
(setf
t16 '((a b a)(a b)(a b b a c)))
(setf
t17 '((a b (c d c)
(a (f g h)(f f h g g)(f g) a b)
(b b b (g g f g)(h g f)(g f h
g)(f f g) a)
(d d c c)(d e) b b a)
((c d)(a b (f g)(f g h))(e d))))
For::
setu, setdf & setint ::
t1, t2
t2, t1
t1, t3
t3, t1
t2, t4
t4, t2
t3, t4
t4, t3
clean
:: t5 through t9 & t14
flatten, countatoms &
countuniqueatoms :: t10 through t17
subset ::
t1, t1
t2, t2
t1, t5
t5, t1
t1, t9
t9, t1
t5, t6
t6, t5
t5, t7
t7, t5
t5, t9
t9, t5
sameset ::
t5, t6
t6, t5
t7, t8
t8, t7
t5, t9
t9, t5
t6, t8
t8, t6
t7, t9
t9, t7
fclean :: t14 through t17