Luhn test of credit card numbers: Difference between revisions

Content added Content deleted
(→‎{{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|Halcyon Calc|4.2.8}}
{{works with|RPL|HP48-C}}
{| class="wikitable"
{| class="wikitable"
! RPL code
! RPL code
Line 5,704: Line 5,704:
|-
|-
|
|
→ card
« 0 → card even
« 0
≪ 0 card SIZE 1 '''FOR''' j
card j DUP SUB STR→
card SIZE 1 '''FOR''' j
'''IF''' j 2 MOD NOT '''THEN '''
card j DUP SUB OBJ→
2 * 10 MOD LAST / FLOOR + '''END'''
'''IF''' even '''THEN'''
+ -1 '''STEP'''
DUP + 10 MOD LASTARG / IP + '''END'''
10 MOD NOT
+ 1 'even' STO-
-1 '''STEP'''
'<span style="color:blue">LUHN?</span>' STO
10 MOD NOT
» » '<span style="color:blue">LUHN?</span>' STO
|
|
<span style="color:blue">LUHN?</span> ''( "card_number" -- boolean ) ''
<span style="color:blue">LUHN?</span> ''( "card_number" -- boolean ) ''
sum = 0 ; loop for j=n to 1
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" } cases
{ "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>