Created
May 15, 2014 19:14
-
-
Save ray1729/68f4feb328c4d68b7b1e to your computer and use it in GitHub Desktop.
Explode string containing ambiguous characters
This file contains 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
(ns playground.explode | |
(:require [clojure.math.combinatorics :refer [cartesian-product]] | |
[clojure.string :as str])) | |
(def ambiguous-chars [#{\O \0} #{\I \L \1}]) | |
(defn ambiguate | |
[c] | |
(or (first (filter #(contains? % c) ambiguous-chars)) | |
[c])) | |
(defn explode | |
[s] | |
(map str/join (apply cartesian-product (map ambiguate s)))) | |
(explode "PHONIC") | |
;;=> ("PHONIC" "PHONLC" "PHON1C" "PH0NIC" "PH0NLC" "PH0N1C") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment