diff options
author | Colin Okay <cbeok@protonmail.com> | 2020-07-11 12:42:23 -0500 |
---|---|---|
committer | Colin Okay <cbeok@protonmail.com> | 2020-07-11 12:42:23 -0500 |
commit | 234a192c3845069d5f26455dfcbe27edc9787fa8 (patch) | |
tree | 14040d32780ad7eb57098d0d58a00bb863af80bd /examples.lisp | |
parent | 9882e084874c5640feeac4390431a450c9edfeec (diff) |
added a few more combinators and and an example
Diffstat (limited to 'examples.lisp')
-rw-r--r-- | examples.lisp | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/examples.lisp b/examples.lisp index 221c78e..df50a23 100644 --- a/examples.lisp +++ b/examples.lisp @@ -118,4 +118,33 @@ vector VEC, one at a time." (zip! (range) (file-lines file)))) -;; find all export expressions in my bashrc file + +;;; Silly Scrambler ;;; + + +(defun pad (str len &optional (pad-char #\Space])) + (let ((i 0)) + (with-output-to-string (out) + (loop :for c :across str :do (incf i) (princ c out)) + (loop :while (< i len) :do (incf i) (princ pad-char out))))) + +(defun scramble (n str) + (assert (< n (length str))) + (let ((str (pad str (* n (ceiling (/ (length str) n)))))) + (concatenate 'string + (apply #'nconc + (mapcar #'collect + (disperse! n (seq str))))))) + +(defun chunk (n str) + (assert (zerop (mod (length str) n))) + (let ((size (/ (length str) n))) + (loop + :for i :below (length str) :by size + :collect (subseq str i (+ i size)) ))) + +(defun descramble (n str) + (concatenate 'string + (collect + (apply #'intersperse! + (mapcar #'seq (chunk n str)))))) |