aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Okay <cbeok@protonmail.com>2020-08-13 09:52:32 -0500
committerColin Okay <cbeok@protonmail.com>2020-08-13 09:52:32 -0500
commit61c06fc10ee2bad8d810d342a707677ede2c5f78 (patch)
tree657f7d25d9cff1bf50c13bccaf606e506716dfe1
parent76ce9621e57a51c4dff7f89f86bf32c105780de7 (diff)
added example
-rw-r--r--examples.lisp15
1 files changed, 15 insertions, 0 deletions
diff --git a/examples.lisp b/examples.lisp
new file mode 100644
index 0000000..7bd44e2
--- /dev/null
+++ b/examples.lisp
@@ -0,0 +1,15 @@
+
+(defpackage #:lt-examples
+ (:use #:cl #:lambda-toosl))
+
+
+;; 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))))))