Skip to content

Instantly share code, notes, and snippets.

@Ferada
Created June 8, 2020 21:47
Show Gist options
  • Save Ferada/f63c00334785c4b0e113a938ccad3b37 to your computer and use it in GitHub Desktop.
Save Ferada/f63c00334785c4b0e113a938ccad3b37 to your computer and use it in GitHub Desktop.
;; c.f. <https://de.wikipedia.org/wiki/Steuerliche_Identifikationsnummer#Aufbau_der_Identifikationsnummer>
(defun check-steuer-id (id)
(let ((product 0))
(loop
with digits = (mapcar (lambda (digit) (parse-integer (string digit))) (coerce (format NIL "~D" id) 'list))
for i from 1 to 10
for digit = (elt digits (1- i))
for sum = (mod (+ digit product) 10)
when (zerop sum)
do (setf sum 10)
do (setf product (mod (* sum 2) 11))
finally
(let ((check-digit (- 11 product)))
(when (eql check-digit 10)
(setf check-digit 0))
(return (eql (elt digits 10) check-digit))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment