SHARE
TWEET

Untitled

a guest Oct 21st, 2019 70 in 12 hours
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defn clean-for-encode
  2.   [coll]
  3.   (if (= 1 (count coll))
  4.     (str (first coll))
  5.     (str (count coll) (first coll))))
  6.  
  7. (defn run-length-encode
  8.   [plain-text]
  9.   (let [partioned (partition-by identity plain-text)]
  10.     (apply str (map clean-for-encode partioned))))
  11.  
  12. (defn parse-for-decode
  13.   [s]
  14.   (if (= 1 (count s))
  15.     s
  16.     (vector (Long/parseLong (apply str (butlast s)))
  17.             (str (last s)))))
  18.  
  19. (defn clean-for-decode [coll]
  20.   (if (= 1 (count coll))
  21.     coll
  22.     (apply str (repeat (first coll) (second coll)))))
  23.  
  24. (defn run-length-decode
  25.   [cipher-text]
  26.   (let [regexed (re-seq #"\d+[a-zA-Z\s]|[a-zA-Z\s]" cipher-text)
  27.         parsed-regex (map parse-for-decode regexed)]
  28.     (apply str (map clean-for-decode parsed-regex))))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top