Skip to content

Instantly share code, notes, and snippets.

@refaktor
Last active February 7, 2022 09:28
Show Gist options
  • Save refaktor/ad757698b82edc6d1da3dfc95634f243 to your computer and use it in GitHub Desktop.
Save refaktor/ad757698b82edc6d1da3dfc95634f243 to your computer and use it in GitHub Desktop.
(ns clojpression-puzzle
(:require [clojure.test :refer [is]]))
(def compress (partial transduce (comp (partition-by identity)
(mapcat (fn [[c & _ :as cs]]
[(count cs) c])))
str))
(defn run [& _]
(is (= (compress "AAABBAAC") "3A2B2A1C")))
compress: fn1 { .partition { , } |map { :a .length .concat first a } |join }
"AAAABBCCC" .compress .assert-equal "4A2B3C"
compress-a: fn1 { .partition { , } |fold 'acc "" { :a .length .concat first a |concat* acc } }
compress-b: fn1 { .partition { , } |fold 'acc "" { :a { acc length a first a } .eval .join } }
"AAAABBCCC" .compress-a .assert-equal "4A2B3C"
"AAAABBCCC" .compress-b .assert-equal "4A2B3C"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment