SHARE
TWEET

word-breaks

mamboking Aug 12th, 2011 175 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)))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top