Last active
November 27, 2018 04:46
A quick-n-dirty solution to https://techdevguide.withgoogle.com/paths/advanced/compress-decompression/#code-challenge
This file contains hidden or 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
(ql:quickload :cl-ppcre) | |
(defun decompress (in) | |
(multiple-value-bind (string matchp) | |
(cl-ppcre:regex-replace "([0-9]+)\\[([^][]*)\\]" | |
in | |
(lambda (match reg1 reg2) | |
(declare (ignorable match)) | |
(format nil "~v@{~A~:*~}" (parse-integer reg1) reg2)) | |
:simple-calls t | |
:preserve-case t) | |
(if matchp | |
(decompress string) | |
string))) | |
;; (decompress "3[abc]4[ab]c") => "abcabcabcababababc" | |
;; (decompress "2[3[a]b]") => "aaabaaab" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment