Skip to content

Instantly share code, notes, and snippets.

@gigamonkey
Created April 18, 2017 04:24
Show Gist options
  • Save gigamonkey/b05e71c919c7574b9b8b8c95881ab555 to your computer and use it in GitHub Desktop.
Save gigamonkey/b05e71c919c7574b9b8b8c95881ab555 to your computer and use it in GitHub Desktop.
Got nerd sniped by sylphon
import Data.List
dict = [ "this", "th", "is", "famous", "Word", "break", "b", "r", "e", "a", "k", "br", "bre", "brea", "ak", "problem" ]
string = "Wordbreakproblem"
solve d s = map (intercalate " " . reverse . fst) $ finish (concatMap (starts d)) [([], s)]
starts _ x@(ws, []) = [x]
starts d (ws, s) = [(w:ws, drop (length w) s) | w <- d, w `isPrefixOf` s]
finish fn x = if fn x == x then x else finish fn (fn x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment