Last active
February 7, 2022 09:28
-
-
Save refaktor/ad757698b82edc6d1da3dfc95634f243 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compress: fn1 { .partition { , } |map { :a .length .concat first a } |join } | |
"AAAABBCCC" .compress .assert-equal "4A2B3C" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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