This repository has been archived on 2024-12-15. You can view files and clone it, but cannot push or open issues or pull requests.
CIS194/luhn.lhs
2016-03-25 16:54:43 +01:00

14 lines
360 B
Plaintext

This is an implementation of the Luhn Algorithm. It's used to validate credit card numbers.
> lastDigit :: Integer -> Integer
> lastDigit n = mod n 10
> dropLastDigit :: Integer -> Integer
> dropLastDigit n = div n 10
> toRevDigits :: Integer -> [Integer]
> toRevDigits n
> | n < 1 = []
> | otherwise = lastDigit(n) : toRevDigits(dropLastDigit(n))