Luhn test of credit card numbers: Difference between revisions
Content deleted Content added
→{{header|Octave}}: change int2str to mat2str because mat2str supports larger numbers |
Updated D versions |
||
Line 464:
<lang d>import std.algorithm;
uint sum;
foreach_reverse (i, n; num) {
sum += ((num.length - i) & 1) ? ord : ord / 5 + (2 * ord) % 10;
}
Line 474:
void main() {
"1234567812345678", "1234567812345670"];
assert(equal(map!luhnTest(data), [true, false, false, true]));
}</lang>
Line 483:
<lang d>import std.stdio;
T a, b;
Line 493:
bool opBinaryRight(string op="in")(in T x) pure nothrow {
return x >= a && x <= b;
}
pure nothrow invariant() {
assert(a <= b);
}
}
|