Luhn test of credit card numbers: Difference between revisions

Simplified D code
(Added BBC BASIC)
(Simplified D code)
Line 465:
<lang d>import std.algorithm;
 
pure bool luhnTest(constin string numbernum) {
uint len = number.lengthsum;
foreach_reverse (i, n; num) {
uint sum;
const uint ord = n - '\u0030';
foreach_reverse(i, n; number) {
sum += ((num.length - uinti) & 1) ? ord =: nord -/ 5 + (2 * ord) % '\u0030'10;
}
if ((len - i) & 1) {
return sum % 10 sum +== ord0;
} else {
sum += ord / 5 + (2 * ord) % 10;
}
}
return sum % 10 == 0;
}
 
void main() {
unittest {
auto rdata = map!luhnTest(["49927398716", "49927398717","1234567812345678", "1234567812345670"]);
"1234567812345678", "1234567812345670"];
assert(equal(rmap!luhnTest(data), [true, false, false, true]));
}</lang>
 
=={{header|F Sharp|F#}}==
<lang fsharp>let luhn (s:string) =
Anonymous user