Advertisement
mamboking

word-breaks

Aug 12th, 2011
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;; word-breaks
  2. (def dict #{"a" "apple" "applepie" "base" "baseball"
  3.             "bat" "gift" "i" "pi" "pie" "twist"})
  4.  
  5. (defn permute [ss]
  6.   (distinct
  7.    (mapcat identity
  8.            (let [cnt (count ss)
  9.                  coll (take cnt (iterate rest ss))]
  10.              (for [n (range 1 (inc cnt))]
  11.                (mapcat (fn [x]
  12.                          (map (fn [y] (apply str y))
  13.                               (partition n x)))
  14.                        coll))))))
  15.  
  16. (defn find-word-bounds [ss]
  17.   (filter dict (permute ss)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement