Skip to content

Instantly share code, notes, and snippets.

@arademaker
Created September 14, 2011 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arademaker/1215526 to your computer and use it in GitHub Desktop.
Save arademaker/1215526 to your computer and use it in GitHub Desktop.
Verifying ISSN's Check digit using Lisp
(defun check-issn (str)
" Parse a string of 8 digits in the format NNNN-NNNN representing an
ISSN number. The last N can be an X representing 10. "
(let ((digits (remove nil (loop for char across str
collect (cond ((equal char #\X) 10)
((equal char #\-) nil)
(t (parse-integer (string char))))))))
(if (not (equal (length digits) 8))
nil
(equal 0 (mod (loop for i from 8 downto 1
for j in digits
summing (* j i)) 11)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment