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.180 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.179 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.178 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.177 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.176 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.175 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.174 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.173 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.172 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.171 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.170 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.169 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.167 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.166 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.165 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.164 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.163 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.162 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.161 tracks/lfe/exercises/luhn/src/example.lfe
trackler-2.2.1.160 tracks/lfe/exercises/luhn/src/example.lfe