Sha256: b7c8ae5a9821eff0d907d082b337975037b9d862238604fd9a81fcbd786b85cd

Contents?: true

Size: 572 Bytes

Versions: 121

Compression:

Stored size: 572 Bytes

Contents

(ns run-length-encoding)

(defn run-length-encode 
  "encodes a string with run-length-encoding"
  [s]
  (apply str
         (for
           [ x (partition-by identity s)]
           (str
             (when-not (= 1 (count x)) (count x)) (first x)))))

(defn run-length-decode 
  "decodes a run-length-encoded string"
  [s]
  (->> s
       (re-seq #"[0-9]+.|[a-zA-Z\s]")
       (map #(if (= (count %) 1) (str "1" %) %))
       (map #(list (Integer. (reduce str "" (butlast %))) (str (last %))))
       (map #(apply str (repeat (first %) (second %))))
       (reduce str)))

Version data entries

121 entries across 121 versions & 1 rubygems

Version Path
trackler-2.2.1.98 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.97 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.96 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.95 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.94 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.93 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.92 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.91 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.90 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.89 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.88 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.87 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.86 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.85 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.84 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.83 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.82 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.81 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.80 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.79 tracks/clojure/exercises/run-length-encoding/src/example.clj