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.180 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.179 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.178 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.177 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.176 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.175 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.174 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.173 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.172 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.171 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.170 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.169 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.167 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.166 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.165 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.164 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.163 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.162 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.161 tracks/clojure/exercises/run-length-encoding/src/example.clj
trackler-2.2.1.160 tracks/clojure/exercises/run-length-encoding/src/example.clj