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

Version Path
trackler-2.2.1.119 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.118 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.117 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.116 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.115 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.114 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.113 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.111 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.110 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.109 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.108 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.107 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.106 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.105 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.104 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.103 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.102 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.101 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.100 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.99 tracks/lfe/exercises/luhn/src/example.lfe