Can I just check... This looks for every character in the requirement string must be there, and it doesn't matter which order, right? So my understanding is that the tests should give:
abc = 'abc' pattern = regex_contains_all(abc)
bool(re.match(pattern, 'bca')) => true bool(re.match(pattern, 'baczzz')) => true bool(re.match(pattern, 'ac')) => false bool(re.match(pattern, 'cb')) => false
bool(re.match(pattern, 'bca')) => true
bool(re.match(pattern, 'baczzz')) => true
bool(re.match(pattern, 'ac')) => false
bool(re.match(pattern, 'cb')) => false
Assuming the above is OK, then here's my Clojure solution:
(require '[clojure.string :as s]) (defn permute [a] (or (seq (mapcat #(map (partial cons %) (permute (remove #{%} a))) a)) [[]])) (defn regex-contains-all [input] (str "(" (s/join ")|(" (map (partial s/join ".*") (permute input))) ")"))
Apologies for writing code that looks like line noise.
Given an input of "abc" then it will generate:
(regex-contains-all "abc") "(a.*b.*c)|(a.*c.*b)|(b.*a.*c)|(b.*c.*a)|(c.*a.*b)|(c.*b.*a)"
This gives the test results that I describe in the previous comment.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Can I just check...
This looks for every character in the requirement string must be there, and it doesn't matter which order, right? So my understanding is that the tests should give:
bool(re.match(pattern, 'bca')) => true
bool(re.match(pattern, 'baczzz')) => true
bool(re.match(pattern, 'ac')) => false
bool(re.match(pattern, 'cb')) => false
Assuming the above is OK, then here's my Clojure solution:
Apologies for writing code that looks like line noise.
Given an input of "abc" then it will generate:
This gives the test results that I describe in the previous comment.