Skip to content

Instantly share code, notes, and snippets.

@mpasternacki
Created January 9, 2012 19:42
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mpasternacki/e4d81989ba2f2e119a4d to your computer and use it in GitHub Desktop.
(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)
(mapcar
#'(lambda (subvariations)
(concatenate 'string elt subvariations))
(variations (remove elt list) (1- num))))
list))))
(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