How to resolve the algorithm Luhn test of credit card numbers step by step in the Action! 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 Action! 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 Action! programming language
Source code in the action! programming language
PROC ReverseDigits(CHAR ARRAY n,rev)
BYTE i,j
i=n(0)
WHILE i>0 AND n(i)='0
DO
i==-1
OD
j=1
WHILE i>0
DO
rev(j)=n(i)
j==+1 i==-1
OD
rev(0)=j-1
RETURN
BYTE FUNC SumOddDigits(CHAR ARRAY n)
BYTE sum,i
sum=0
FOR i=1 TO n(0) STEP 2
DO
sum==+ValB(n(i))
OD
RETURN(sum)
BYTE FUNC SumEvenDigitsMultiplied(CHAR ARRAY n)
BYTE sum,i,v
sum=0
FOR i=2 TO n(0) STEP 2
DO
v=ValB(n(i))*2
IF v>9 THEN v==-9 FI
sum==+v
OD
RETURN(sum)
BYTE FUNC Luhn(CHAR ARRAY n)
CHAR ARRAY rev(20)
BYTE s1,s2
ReverseDigits(n,rev)
s1=SumOddDigits(rev)
s2=SumEvenDigitsMultiplied(rev)
IF (s1+s2) MOD 10=0 THEN
RETURN(1)
FI
RETURN(0)
PROC Test(CHAR ARRAY n)
PrintF("%S is ",n)
IF Luhn(n) THEN
PrintE("valid")
ELSE
PrintE("invalid")
FI
RETURN
PROC Main()
Test("49927398716")
Test("49927398717")
Test("1234567812345678")
Test("1234567812345670")
RETURN
You may also check:How to resolve the algorithm Soundex step by step in the Java programming language
You may also check:How to resolve the algorithm Dining philosophers step by step in the Ruby programming language
You may also check:How to resolve the algorithm The Twelve Days of Christmas step by step in the D programming language
You may also check:How to resolve the algorithm Rosetta Code/Rank languages by popularity step by step in the AWK programming language
You may also check:How to resolve the algorithm Unicode strings step by step in the Bracmat programming language