Skip to content

Instantly share code, notes, and snippets.

@beckyconning
Created August 5, 2017 23:31
Show Gist options
  • Save beckyconning/e74682e7a1f9a137ba464a178eee0cee to your computer and use it in GitHub Desktop.
Save beckyconning/e74682e7a1f9a137ba464a178eee0cee to your computer and use it in GitHub Desktop.
module Codewars.Kata.Dubstep where
import Prelude
import Data.List (unwords)
import Text.Parsec (many1, manyTill, try, anyChar, string, parse, many, skipMany, (<|>))
-- unwords . filter (not . null) . splitOn "WUB"
-- The above is clearly the stronger solution however parser combinators are cool.
songDecoder :: String -> String
songDecoder =
either show unwords . parse song ""
song =
(skipMany $ try seperator) *> (many $ try stringFollowedBySeperator <|> nonEmptyString)
stringFollowedBySeperator =
manyTill anyChar (many1 $ try seperator)
nonEmptyString =
many1 anyChar
seperator =
string "WUB"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment