Skip to content

Instantly share code, notes, and snippets.

@TN1ck
Last active December 16, 2015 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TN1ck/5404985 to your computer and use it in GitHub Desktop.
Save TN1ck/5404985 to your computer and use it in GitHub Desktop.
(def dates [[14 4] [12 4] [15 3] [13 3] [10 3] [1 1]])
(defn get-num-date [[day month]]
(+ month (* 0.1 day)))
(defn part-dates
([coll]
(let [curdate (apply max-key get-num-date coll)]
(part-dates coll curdate)))
([coll [day month]]
(let [mindate (get-num-date (vector day (dec month)))
fcoll (group-by #(>= (get-num-date %) mindate) coll)]
(if (empty? fcoll)
'()
(filter (complement nil?)
(concat
(vector (fcoll true))
(part-dates (fcoll false)
(vector
(dec month)
(dec day)))))))))
(part-dates dates) ; -> ([[14 4] [12 4] [15 3]] [[13 3] [10 3]] [[1 1]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment