Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Explode string containing ambiguous 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