How to resolve the algorithm Luhn test of credit card numbers step by step in the Draco 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 Draco 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 Draco programming language
Source code in the draco programming language
proc nonrec luhn(*char num) bool:
[10] byte map = (0, 2, 4, 6, 8, 1, 3, 5, 7, 9);
byte total, digit;
*char start;
bool even;
start := num;
total := 0;
even := true;
while num* /= '\e' do num := num + 1 od;
while
num := num - 1;
num >= start
do
digit := num* - '0';
even := not even;
if even then digit := map[digit] fi;
total := total + digit
od;
total % 10 = 0
corp
proc nonrec test(*char num) void:
writeln(num, ": ", if luhn(num) then "pass" else "fail" fi)
corp
proc nonrec main() void:
test("49927398716");
test("49927398717");
test("1234567812345678");
test("1234567812345670")
corp
You may also check:How to resolve the algorithm Split a character string based on change of character step by step in the Racket programming language
You may also check:How to resolve the algorithm Vigenère cipher step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Loops/Break step by step in the Ursa programming language
You may also check:How to resolve the algorithm Bulls and cows step by step in the UNIX Shell programming language
You may also check:How to resolve the algorithm Align columns step by step in the Lambdatalk programming language