Skip to content
Create a gist now

Instantly share code, notes, and snippets.

@mpasternacki /YMD.lisp secret

(defun lvariations (list num)
(if (or (zerop num) (null list))
(list nil)
(loop for elt in list
nconc (loop for subvariation in (lvariations (remove elt list) (1- num))
collect (concatenate 'string elt subvariation)))))
(defun l-the-regexp-elements ()
(nconc (delete-duplicates
(loop for i from 2 to 3
nconc (loop for set in '(("YYYY" "MM" "DD") ("YY" "MM" "DD"))
nconc (lvariations set i)))
:test #'string=)
(list "YYYY" "YY" "MM" "DD")))
(defun variations (list &optional (num (length list)))
(if (or (zerop num) (null list))
(list nil)
(apply #'nconc
(mapcar #'(lambda (elt)
#'(lambda (subvariations)
(concatenate 'string elt subvariations))
(variations (remove elt list) (1- num))))
(defun the-regexp-elements ()
(delete-duplicates (nconc
(variations '("YYYY" "MM" "DD") 3)
(variations '("YYYY" "MM" "DD") 2)
(list "YYYY" "MM" "DD")
(variations '("YY" "MM" "DD") 3)
(variations '("YY" "MM" "DD") 2)
(list "YY"))
:test #'string=))
(defun the-regexp ()
(format nil "~{~A~^|~}" (the-regexp-elements)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.