Exercise 05 Sets - MikeyYeahYeah/clojure-koans GitHub Wiki
Exercise 05 - Sets
Creating a set
A set in clojure means a Mathmetical set. It will remove and recurring numbers. You can create a set using the following syntax:
- #(1 2 3)
- (set '(1 2 3))
Working with Sets
You can count a set
(count #{1 2 3})
;;=> 3
A set is a Mathematical Set
(set '(1 1 2 2 3 3 4 4 5 5))
;;=> #{1 2 3 4 5}
Finding the Union of 2 Sets
(set/union #{1 2 3 4} #{2 3 5})
;;=> #{1 2 3 4 5}
Finding the Intersection of 2 Sets
(set/intersection #{1 2 3 4} #{2 3 5})
;;=> #{2 3}
Finding the Difference of 2 Sets
(set/difference #{1 2 3 4 5} #{2 3 5})
;;=> #{1 4}