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

Source code in the ceylon programming language

shared void run() {
	value numbers = "49927398716
	                 49927398717
	                 1234567812345678
	                 1234567812345670";
	for(number in numbers.lines) {
		print("``number`` passes? ``luhn(number)``");
	}
}

shared Boolean luhn(String number) {
	value digits = number
			.reversed
			.map(Character.string)
			.map(Integer.parse)
			.narrow();
	value s1 = sum { 0, *digits.by(2) };
	value s2 = sum {
		0,
		*digits
			.skip(1)
			.by(2)
			.map(curry(times)(2))
			.map((Integer element) => element / 10 + element % 10)
	};
	return (s1 + s2) % 10 == 0;
}


  

You may also check:How to resolve the algorithm Deming's funnel step by step in the Swift programming language
You may also check:How to resolve the algorithm FizzBuzz step by step in the Gambas programming language
You may also check:How to resolve the algorithm Ternary logic step by step in the Ada programming language
You may also check:How to resolve the algorithm Color of a screen pixel step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Active Directory/Search for a user step by step in the ooRexx programming language