Skip to content

Instantly share code, notes, and snippets.

Created Jan 9, 2012
What would you like to do?
(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