Created
September 11, 2017 17:08
-
-
Save featheredtoast/86520688ed6337fdd7815b15bbb283b9 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 hidden or 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 [partition-even (if (even? (count coll)) (count coll) (dec (count coll))) | |
| coll-sizes (range partition-even 0 -2) | |
| candidates (reduce concat (map #(partition % 1 coll) coll-sizes)) | |
| candidates-group (map (juxt identity (partial group-by integer?)) candidates) | |
| match (some | |
| (fn [[candidate count-map]] | |
| (and (= (count (count-map false)) (count (count-map true))) candidate)) candidates-group)] | |
| match)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment