How to resolve the algorithm Luhn test of credit card numbers step by step in the Arturo 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 Arturo 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 Arturo programming language
Source code in the arturo programming language
digits: function [n][
res: new []
while -> n > 0 [
'res ++ n % 10
n: n / 10
]
res
]
luhn?: function [n][
s1: new 0
s2: new 0
loop.with: 'i digits n 'd [
if? even? i -> 's1 + d
else [
'd * 2
if d > 9 -> 'd - 9
's2 + d
]
]
zero? (s1 + s2) % 10
]
print luhn? 49927398716
print luhn? 49927398717
print luhn? 1234567812345678
print luhn? 1234567812345670
You may also check:How to resolve the algorithm Multisplit step by step in the zkl programming language
You may also check:How to resolve the algorithm Integer comparison step by step in the Nanoquery programming language
You may also check:How to resolve the algorithm Same fringe step by step in the Java programming language
You may also check:How to resolve the algorithm Permutation test step by step in the Delphi programming language
You may also check:How to resolve the algorithm Range extraction step by step in the Julia programming language