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

Source code in the actionscript programming language

function isValid(numString:String):Boolean
{
	var isOdd:Boolean = true;
	var oddSum:uint = 0;
	var evenSum:uint = 0;
	for(var i:int = numString.length - 1; i >= 0; i--)
	{
		var digit:uint = uint(numString.charAt(i))
		if(isOdd) oddSum += digit;
		else evenSum += digit/5 + (2*digit) % 10;
		isOdd = !isOdd;
	}
	if((oddSum + evenSum) % 10 == 0) return true; 
	return false;
}

trace(isValid("49927398716"));
trace(isValid("49927398717"));
trace(isValid("1234567812345678"));
trace(isValid("1234567812345670"));


  

You may also check:How to resolve the algorithm Man or boy test step by step in the Scala programming language
You may also check:How to resolve the algorithm Last Friday of each month step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Interactive programming (repl) step by step in the Elixir programming language
You may also check:How to resolve the algorithm The Twelve Days of Christmas step by step in the Eiffel programming language
You may also check:How to resolve the algorithm Population count step by step in the Ruby programming language