Based on Brent Yorgey's CIS194 Credit Card Validation homework assignment.
root
Validating Credit Card Numbers
Based on Brent Yorgey's CIS 194 first homework assignment.
Have you ever wondered how websites validate your credit card
number when you shop online? They don’t check a massive database
of numbers, and they don’t use magic. In fact, most credit providers
rely on a checksum formula for distinguishing valid numbers from
random collections of digits (or typing mistakes).
In this module, I implemented the validation algorithm for
credit cards. It follows these steps:
•
Double the value of every second digit beginning from the right.
That is, the last digit is unchanged; the second-to-last digit is doubled;
the third-to-last digit is unchanged; and so on. For example,
[1,3,8,6] becomes [2,3,16,6].
•
Add the digits of the doubled values and the undoubled dig-
its from the original number. For example,
[2,3,16,6] becomes 2+3+1+6+6 = 18.
Calculate the remainder when the sum is divided by 10.
For the above example, the remainder would be 8.
If the result equals 0, then the number is valid.
How to install:
cabal install --prefix=$HOME --user