How to resolve the algorithm Luhn test of credit card numbers step by step in the Lasso 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 Lasso 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 Lasso programming language
Source code in the lasso programming language
#!/usr/bin/lasso9
define luhn_check(number) => {
local(
rev = #number->asString,
checksum = 0
)
#rev->reverse
iterate(#rev, local(digit)) => {
if((loop_count % 2) == 0) => {
#checksum += (2 * integer(#digit))
integer(#digit) >= 5 ? #checksum -= 9
else
#checksum += integer(#digit)
}
}
(#checksum % 10) != 0 ? return false
return true
}
stdoutnl(luhn_check(49927398716)) // true
stdoutnl(luhn_check(49927398717)) // false
stdoutnl(luhn_check(1234567812345678)) // false
stdoutnl(luhn_check(1234567812345670)) // true
You may also check:How to resolve the algorithm Reduced row echelon form step by step in the Perl programming language
You may also check:How to resolve the algorithm Write to Windows event log step by step in the D programming language
You may also check:How to resolve the algorithm Run-length encoding step by step in the TUSCRIPT programming language
You may also check:How to resolve the algorithm Jewels and stones step by step in the Python programming language
You may also check:How to resolve the algorithm Pragmatic directives step by step in the Ada programming language