How to resolve the algorithm Luhn test of credit card numbers step by step in the NetRexx 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 NetRexx 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 NetRexx programming language
Source code in the netrexx programming language
class LuhnTest
method main(args=String[]) static
cc = 0
cc[1] = '49927398716'
cc[2] = '49927398717'
cc[3] = '1234567812345678'
cc[4] = '1234567812345670'
loop k=1 while cc[k] <> 0
r = checksum(cc[k])
if r==0 then say cc[k].right(20) 'passed'
else say cc[k].right(20) 'failed'
end
-- Luhn algorithm checksum for credit card numbers
method checksum(t) static
if t.length()//2 then t = '0't --pad # on left with 0
t = t.reverse()
s = 0
loop j = 1 to t.length()-1 by 2
q = 2*t.substr(j+1,1)
if q>9 then q = q.left(1) + q.right(1)
s= s+t.substr(j,1)+q
end
return s//10\==0
You may also check:How to resolve the algorithm Call a function in a shared library step by step in the Ada programming language
You may also check:How to resolve the algorithm Primality by Wilson's theorem step by step in the D programming language
You may also check:How to resolve the algorithm Lucky and even lucky numbers step by step in the zkl programming language
You may also check:How to resolve the algorithm Determine if a string has all unique characters step by step in the Raku programming language
You may also check:How to resolve the algorithm Ackermann function step by step in the LiveCode programming language