Forked from featheredtoast/matching-substring-integer-counts.clj
Created
September 11, 2017 17:51
-
-
Save mlb-/c5beac714ab1e11a4a3d88114e64dda7 to your computer and use it in GitHub Desktop.
Find the largest substring in which the number of integer elements is equal to number of non integer elements.
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
(defn find-subcoll-of-equal-int-nonint [coll] | |
(let [candidates (->> (range 2 (count coll) 2) | |
reverse | |
(map #(-> (partition % 1 coll) | |
(doto println))) | |
(reduce concat) | |
(filter (fn [candidate] | |
(let [{ints true | |
non-ints false} (group-by integer? | |
candidate)] | |
(= (count ints) | |
(count non-ints))))))] | |
(first candidates))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment