Last active
December 16, 2015 08:19
-
-
Save TN1ck/5404985 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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