aboutsummaryrefslogtreecommitdiff
path: root/examples.lisp
blob: 973ebeee4108745b42503295ee2de9154eec50f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14

(defpackage #:lt-examples
  (:use #:cl #:lambda-tools))


;; http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers 
(defun luhn (n)
  (flet ((sum-dig (x) (if (> x 9) (- x 9) x)))
    (>> n #'reverse
        #$(map 'list #'digit-char-p $char)
        #$(mapcar #'*
                (loop :for i :upto (length $digits) :collect (1+ (mod i 2)))
                $digits)
        #$(zerop (mod (apply #'+ (mapcar #'sum-dig $digits)) 10)))))