Skip to content

Instantly share code, notes, and snippets.

@mamboking
Created August 13, 2011 03:39
Show Gist options
  • Save mamboking/1143455 to your computer and use it in GitHub Desktop.
Save mamboking/1143455 to your computer and use it in GitHub Desktop.
Word breaks solution
;; word-breaks
(def dict #{"a" "apple" "applepie" "base" "baseball"
"bat" "gift" "i" "pi" "pie" "twist"})
(defn permute [ss]
(distinct
(mapcat identity
(let [cnt (count ss)
coll (take cnt (iterate rest ss))]
(for [n (range 1 (inc cnt))]
(mapcat (fn [x]
(map (fn [y] (apply str y))
(partition n x)))
coll))))))
(defn find-word-bounds [ss]
(filter dict (permute ss)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment