Jump to content

Luhn test of credit card numbers: Difference between revisions

Add Draco
(Add CLU)
(Add Draco)
Line 2,463:
writefln("%s is %svalid", n, luhnTest(n) ? "" : "not ");
}</lang>
 
=={{header|Draco}}==
<lang draco>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</lang>
{{out}}
<pre>49927398716: pass
49927398717: fail
1234567812345678: fail
1234567812345670: pass</pre>
 
=={{header|EchoLisp}}==
2,114

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.