Tutorial files
This commit is contained in:
commit
e9f43a54fc
13
luhn.lhs
Normal file
13
luhn.lhs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
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))
|
||||||
|
|
Reference in New Issue
Block a user