Created
April 18, 2017 04:24
-
-
Save gigamonkey/b05e71c919c7574b9b8b8c95881ab555 to your computer and use it in GitHub Desktop.
Got nerd sniped by sylphon
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
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