How to resolve the algorithm Luhn test of credit card numbers step by step in the AWK programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Luhn test of credit card numbers step by step in the AWK programming language
Table of Contents
Problem Statement
The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits. Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test:
For example, if the trial number is 49927398716:
Write a function/method/procedure/subroutine that will validate a number with the Luhn test, and use it to validate the following numbers:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Luhn test of credit card numbers step by step in the AWK programming language
Source code in the awk programming language
#!/usr/bin/awk -f
BEGIN {
A[1] = 49927398716;
A[2] = 49927398717;
A[3] = 1234567812345678;
A[4] = 1234567812345670;
A[5] = "01234567897";
A[6] = "01234567890";
A[7] = "00000000000";
for (k in A) print "isLuhn("A[k]"): ",isLuhn(A[k]);
}
function isLuhn(cardno) {
s = 0;
m = "0246813579";
n = length(cardno);
for (k = n; 0 < k; k -= 2) {
s += substr(cardno, k, 1);
}
for (k = n-1; 0 < k; k -= 2) {
s += substr(m, substr(cardno, k, 1)+1, 1);
}
return ((s%10)==0);
}
You may also check:How to resolve the algorithm Euler's identity step by step in the Scala programming language
You may also check:How to resolve the algorithm Test integerness step by step in the Ruby programming language
You may also check:How to resolve the algorithm Iterated digits squaring step by step in the J programming language
You may also check:How to resolve the algorithm Power set step by step in the ATS programming language
You may also check:How to resolve the algorithm S-expressions step by step in the F# programming language