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