Question
{- Applies Luhn's algorithm for numeric ID verification: The Luhn algorithm is used to verify the validity of numeric identifiers commonly used for credit/debit card
{-
Applies Luhn's algorithm for numeric ID verification:
The Luhn algorithm is used to verify the validity of numeric identifiers
commonly used for credit/debit card numbers, government IDs, IMEI numbers,
etc. Given a list of one-digit numbers, it processes them as follows:
1. From right to left, double the value of every other digit. If a
product is greater than 9, subtract 9 from that result.
2. Sum up all the digits (i.e., the results from step 1 and the given values
of the other digits)
3. If the result is evenly divisible by 10, the identifier is valid.
E.g., given the identifier consisting of the numbers [2,7,5,8]:
1. We start by doubling the value of every other number starting from the
right, getting [4,7,10,8]. Since 10 > 9, we subtract 9 from it,
giving us the list [4,7,1,8]
2. Sum up all the digits, giving us: 4+7+1+8 = 20
3. 20 is evenly divisible by 10, so the identifier is valid.
E.g., given the identifier consisting of the numbers [4,6,1,8,5,3,8]
1. Doubling every other value and subtracting 9 when needed gets us
[4,3,1,7,5,6,8]
2. Summing them gets us 34
3. 34 is not evenly divisible by 10, so the identifier is invalid.
Examples:
luhn [2,7,5,8]
=> True
luhn [4,3,1,7,5,6,8]
=> False
luhn [3,9,2,8,6,4,1,7,2,0,5,2]
=> True
-}
luhn :: [Int] -- numeric ID
-> Bool -- True if valid, False otherwise
luhn = undefined
in haskell
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started