How to resolve the algorithm Luhn test of credit card numbers step by step in the UNIX Shell 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 UNIX Shell 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 UNIX Shell programming language
Source code in the unix programming language
function luhn {
typeset n p s t=('0123456789' '0516273849')
while ((-n<${#1})); do
p="${t[n--%2]%${1:n:1}*}"
((s+=${#p}))
done
((s%10))
}
for c in 49927398716 49927398717 1234567812345678 1234567812345670; do
if luhn $c; then
echo $c is invalid
else
echo $c is valid
fi
done
You may also check:How to resolve the algorithm Include a file step by step in the BaCon programming language
You may also check:How to resolve the algorithm Array length step by step in the Transd programming language
You may also check:How to resolve the algorithm Hello world/Standard error step by step in the Nemerle programming language
You may also check:How to resolve the algorithm FASTA format step by step in the BASIC programming language
You may also check:How to resolve the algorithm 100 doors step by step in the Agena programming language