Luhn test of credit card numbers: Difference between revisions
Content added Content deleted
Langurmonkey (talk | contribs) |
Not a robot (talk | contribs) (Add SETL) |
||
Line 6,033: | Line 6,033: | ||
s2Mapping[x[i] + 1]; |
s2Mapping[x[i] + 1]; |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|SETL}}== |
|||
<syntaxhighlight lang="setl">program luhn_test; |
|||
tests := [ |
|||
49927398716, |
|||
49927398717, |
|||
1234567812345678, |
|||
1234567812345670 |
|||
]; |
|||
loop for test in tests do |
|||
print(test, if luhn test then "pass" else "fail" end); |
|||
end loop; |
|||
op luhn(n); |
|||
fac := 2; |
|||
digits := [val d * (fac := 3-fac) : d in reverse str n]; |
|||
return 0 = +/[d - if d>9 then 9 else 0 end : d in digits] mod 10; |
|||
end op; |
|||
end program;</syntaxhighlight> |
|||
{{out}} |
|||
<pre>49927398716 pass |
|||
49927398717 fail |
|||
1234567812345678 fail |
|||
1234567812345670 pass</pre> |
|||
=={{header|Shen}}== |
=={{header|Shen}}== |