Sha256: b235fc8c268b063ea29cc993b24423012af6a3dc72cbd6ee42f27e474c354002
Contents?: true
Size: 786 Bytes
Versions: 396
Compression:
Stored size: 786 Bytes
Contents
(defmodule luhn (export (valid? 1) (create 1) (checksum 1))) (defun valid? (number) (== (rem (checksum number) 10) 0)) (defun create (number) (lists:flatten `(,number ,(- #\: (rem (checksum (++ number "0")) 10))))) (defun checksum (number) (checksum (lists:reverse (lists:filter (lambda (c) (=< #\0 c #\9)) number)) 'odd 0)) (defun checksum ([() _ total] total) ([(cons h reversed-number) 'odd total] (checksum reversed-number 'even (- (+ total h) #\0))) ([(cons h reversed-number) 'even total] (when (< h #\5)) (checksum reversed-number 'odd (+ total (* (- h #\0) 2)))) ([(cons h reversed-number) 'even total] (when (>= h #\5)) (checksum reversed-number 'odd (- (+ total (* (- h #\0) 2)) 9))))
Version data entries
396 entries across 396 versions & 1 rubygems