How to resolve the algorithm Luhn test of credit card numbers step by step in the LiveCode 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 LiveCode 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 LiveCode programming language

Source code in the livecode programming language

function LuhnTest cc
    local s1,evens, s2
    repeat with n = 1 to len(cc)
        if n mod 2 is not 0 then
            add (char -n of cc) to s1
        else
            put (char -n of cc) * 2 into evens
            if evens > 9 then subtract 9 from evens
            add evens to s2
        end if
    end repeat
    return the last char of (s1 + s2) is 0
end LuhnTest

-- test
repeat for each item ccno in "49927398716,49927398717,1234567812345678,1234567812345670"
    put ccno && LuhnTest(ccno) & cr after luhncheck
end repeat
put luhncheck

49927398716 true
49927398717 false
1234567812345678 false
1234567812345670 true

  

You may also check:How to resolve the algorithm Terminal control/Coloured text step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Bitmap/Bresenham's line algorithm step by step in the Wren programming language
You may also check:How to resolve the algorithm Call an object method step by step in the zkl programming language
You may also check:How to resolve the algorithm Multiple distinct objects step by step in the Fortran programming language
You may also check:How to resolve the algorithm Department numbers step by step in the APL programming language