2015-09-13 05:28:39 +00:00
|
|
|
(ns koans.05-sets
|
2015-06-15 02:38:41 +00:00
|
|
|
(:require [koan-engine.core :refer :all]
|
|
|
|
[clojure.set :as set]))
|
2014-01-26 00:04:22 +00:00
|
|
|
|
2010-02-06 23:43:06 +00:00
|
|
|
(meditations
|
2013-03-04 23:30:00 +00:00
|
|
|
"You can create a set by converting another collection"
|
|
|
|
(= #{3} (set __))
|
2010-02-06 23:43:06 +00:00
|
|
|
|
2013-03-04 23:30:00 +00:00
|
|
|
"Counting them is like counting other collections"
|
2010-10-29 15:45:47 +00:00
|
|
|
(= __ (count #{1 2 3}))
|
2010-09-30 23:34:02 +00:00
|
|
|
|
2013-03-04 23:30:00 +00:00
|
|
|
"Remember that a set is a *mathematical* set"
|
2010-07-26 23:20:42 +00:00
|
|
|
(= __ (set '(1 1 2 2 3 3 4 4 5 5)))
|
2010-02-06 23:43:06 +00:00
|
|
|
|
2010-07-26 23:20:42 +00:00
|
|
|
"You can ask clojure for the union of two sets"
|
2015-06-15 02:38:41 +00:00
|
|
|
(= __ (set/union #{1 2 3 4} #{2 3 5}))
|
2010-02-06 23:43:06 +00:00
|
|
|
|
2010-07-26 23:20:42 +00:00
|
|
|
"And also the intersection"
|
2015-06-15 02:38:41 +00:00
|
|
|
(= __ (set/intersection #{1 2 3 4} #{2 3 5}))
|
2010-02-06 23:43:06 +00:00
|
|
|
|
2010-07-26 23:20:42 +00:00
|
|
|
"But don't forget about the difference"
|
2015-06-15 02:38:41 +00:00
|
|
|
(= __ (set/difference #{1 2 3 4 5} #{2 3 5})))
|