Created
August 13, 2011 03:39
-
-
Save mamboking/1143455 to your computer and use it in GitHub Desktop.
Word breaks solution
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
;; 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