Luhn test of credit card numbers: Difference between revisions
Content added Content deleted
m (→{{header|RPL}}: typo) |
(→{{header|RPL}}: corrected major bug) |
||
Line 5,698: | Line 5,698: | ||
=={{header|RPL}}== |
=={{header|RPL}}== |
||
Card numbers shall be entered as strings to avoid any rounding error when testing long ones. |
Card numbers shall be entered as strings to avoid any rounding error when testing long ones. |
||
{{works with| |
{{works with|RPL|HP48-C}} |
||
{| class="wikitable" |
{| class="wikitable" |
||
! RPL code |
! RPL code |
||
Line 5,704: | Line 5,704: | ||
|- |
|- |
||
| |
| |
||
« 0 → card even |
|||
« 0 |
|||
≪ 0 card SIZE 1 '''FOR''' j |
|||
card SIZE 1 '''FOR''' j |
|||
card j DUP SUB OBJ→ |
|||
'''IF''' even '''THEN''' |
|||
+ |
DUP + 10 MOD LASTARG / IP + '''END''' |
||
+ 1 'even' STO- |
|||
-1 '''STEP''' |
|||
⚫ | |||
10 MOD NOT |
|||
⚫ | |||
| |
| |
||
<span style="color:blue">LUHN?</span> ''( "card_number" -- boolean ) '' |
<span style="color:blue">LUHN?</span> ''( "card_number" -- boolean ) '' |
||
sum = 0 |
sum = 0 |
||
loop for j=n to 1 |
|||
digit = card[j] |
digit = card[j] |
||
if even digit |
if even digit |
||
multiply it by 2 and add digits |
multiply it by 2 and add digits |
||
sum += digit |
sum += digit ; reverse parity flag |
||
return not(sum mod 10) |
return not(sum mod 10) |
||
|} |
|} |
||
{ "49927398716" "49927398717" "1234567812345678" "1234567812345670" } 1 « <span style="color:blue">LUHN?</span> » DOLIST |
|||
≪ { } 1 cases SIZE '''FOR''' j cases j GET <span style="color:blue">LUHN?</span> + '''NEXT''' ≫ ≫ EVAL |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |