Skip to content

Instantly share code, notes, and snippets.

@featheredtoast
Created September 11, 2017 17:08
Show Gist options
  • Select an option

  • Save featheredtoast/86520688ed6337fdd7815b15bbb283b9 to your computer and use it in GitHub Desktop.

Select an option

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.
(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