Luhn test of credit card numbers: Difference between revisions

add Refal
(add Refal)
Line 5,473:
ok 4 - 1234567812345670 passes the Luhn test.</pre>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <Test '49927398716'>
<Test '49927398717'>
<Test '1234567812345678'>
<Test '1234567812345670'>;
};
 
Test {
e.Digits = <Prout e.Digits ': ' <Luhn e.Digits>>;
};
 
Luhn {
(s.Sum) e.Digits s.Even s.Odd,
<Mul 2 <Numb s.Even>>: s.Even2,
<Divmod s.Even2 10>: (s.EvenD1) s.EvenD2,
<+ s.EvenD1 s.EvenD2>: s.EvenV,
<+ <Numb s.Odd> s.EvenV>: s.Step
= <Luhn (<+ s.Sum s.Step>) e.Digits>;
(s.Sum) s.Odd = <Luhn (<+ s.Sum <Numb s.Odd>>)>;
(s.Sum), <Divmod s.Sum 10>: (s.Rest) s.Last,
s.Last: {
0 = Valid;
s.X = Invalid;
};
e.Digits = <Luhn (0) e.Digits>;
};</syntaxhighlight>
{{out}}
<pre>49927398716: Valid
49927398717: Invalid
1234567812345678: Invalid
1234567812345670: Valid</pre>
=={{header|REXX}}==
===version 1===
2,114

edits