Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mlb-/c5beac714ab1e11a4a3d88114e64dda7 to your computer and use it in GitHub Desktop.
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.
(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