Skip to content

Instantly share code, notes, and snippets.

@qinshulei
Created September 27, 2017 03:36
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 qinshulei/b0fb408c9a90aebbf9e98ef2f624490b to your computer and use it in GitHub Desktop.
Save qinshulei/b0fb408c9a90aebbf9e98ef2f624490b to your computer and use it in GitHub Desktop.
第18位身份证号生成算法
(require 'cl-lib)
(defun personal-identity-last-bit (n)
;; 1. S = sum(item(i) * weight(i))
;; 2. Y = mod(S, 11)
;; 3. M = map(Y, r)
(let ((bits (mapcar 'string-to-number
(mapcar 'char-to-string n)))
(weights '(7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2))
(map-result '(1 0 "X" 9 8 7 6 5 4 3 2)))
(nth (% (apply '+ (cl-mapcar #'* bits weights )) 11) map-result)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment