Validate International Securities Identification Number: Difference between revisions
Validate International Securities Identification Number (view source)
Revision as of 21:41, 14 June 2024
, 15 days ago→{{header|langur}}
(Add bruijn) |
Langurmonkey (talk | contribs) |
||
(10 intermediate revisions by 4 users not shown) | |||
Line 2,102:
=={{header|langur}}==
The luhn test is repeated here for simplicity
<syntaxhighlight lang="langur">
val luhntest = fn(s) {
val
val
val oddeven = len(numbers) rem 2
for[=0]
_for += if
numbers[i]
} else {
t[numbers[i]+1]
}
} div 10
}
val
}
val
"US0378331005": true,
"US0373831005": false,
Line 2,129 ⟶ 2,134:
}
for
val
write
writeln if(
}
</syntaxhighlight>
{{out}}
Line 2,698 ⟶ 2,704:
=={{header|REXX}}==
<syntaxhighlight lang="rexx">
Parse Arg z /*obtain ISINs from the C.L. */
If z='' Then
z='US0378331005 US0373831005 U50378331005 US03378331005',
'US037*331005',
'XY037833100Z AU0000XVGZA3 AU0000VXGZA3 FR0000988040'
valid='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' /*X must contain 0-->9 A-->Z */
Do n=1 To words(z) /* [?] process all specified ISINs.*/
x=word(z,n)
p=verify(x,valid,'N')
If p>0 Then msg='invalid character in position' p':' substr(x,p,1)
Else Do
dd=''
Do k=1 To length(x)
End
msg=''
Select
When length(x)\==12 Then msg='not exactly 12 chars'
When \datatype(right(x,1),'W') Then msg='last character is not a digit'
Otherwise
If \luhn(dd) Then msg='does
End
End
If msg='' Then
Say right(x,15) ' valid' /* display the positive message. */
Else
Say right(x,15) 'not valid:' msg /* display the problem */
End /*n*/
Exit /*stick a fork in it, we're all done */
/*-----------------------------------------------------------------------------------*/
luhn: Procedure
Parse Arg x /* get credit card number; */
dsum=0 /* zero digit sum. */
y=reverse(left(0,length(x)//2)x) /* add leading zero If needed & reverse */
Do j=1 To length(y)-1 By 2
_=2*substr(y,j+1,1)
dsum=dsum+substr(y,j,1)+left(_,1)+substr(_,2,1,0)
End
Return right(dsum,1)==0 /* Return 1 if number passed Luhn test */</syntaxhighlight>
{{out|output|text= when using the default inputs:}}
<pre>
US0373831005 not valid: does not pass the Luhn test
U50378331005 not valid: not starting with 2 capital chars
US03378331005 not valid: not exactly 12 chars
US037*331005 not valid: invalid character in position 6: *
XY037833100Z not valid: last character is not a digit
AU0000VXGZA3 valid
FR0000988040 valid
</pre>
Line 2,828 ⟶ 2,853:
AU0000VXGZA3 -> Valid
FR0000988040 -> Valid
</pre>
=={{header|RPL}}==
<code>LUHN?</code> is defined at [[Luhn test of credit card numbers#RPL|Luhn test of credit card numbers]]
{{works with|RPL|HP48-R}}
« '''IF''' DUP SIZE 12 ≠ '''THEN''' DROP 0
'''ELSE'''
""
1 3 PICK SIZE '''FOR''' j
OVER j DUP SUB
'''IF''' "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" SWAP POS '''THEN''' LASTARG 1 - + '''END'''
'''NEXT'''
<span style="color:blue">LUHN?</span>
{ "AD" "AT" "AU" "BE" "CA" "DE" "ES" "FR" "GB" "HK" "IT" "US" "ZW" } <span style="color:grey">@ country codes sample </span>
ROT 1 2 SUB POS AND
'''END'''
» '<span style="color:blue">ISIN?</span>' STO
{"US0378331005" "US0373831005" "U50378331005" "US03378331005" "AU0000XVGZA3" "AU0000VXGZA3" "FR0000988040"}
1 « <span style="color:blue">ISIN?</span> » DOLIST
{{out}}
<pre>
1: { 1 0 0 0 1 1 1 }
</pre>
Line 3,243 ⟶ 3,291:
</syntaxhighlight>
=={{header|Uiua}}==
<syntaxhighlight lang="uiua">
Base ← "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Luhn ← =0◿10+⊃(/+⊢|/+∵(⍥(-9)>9.×2)⊡1)⍉⬚0↯∞_2⇌
Checksum ← Luhn≡⋕/◇⊂≡(□°⋕⊗)⊙(¤Base)
Format ← ××⊃(/×≡(≥@A)↙2|=12⧻|/↧∊:Base)
Valid ← ×⊃(Format|Checksum)
Tests ← {
"AU0000XVGZA3"
"US0378331005"
"US0373831005" # twiddled
"U50378331005" # 5 rather than S
"US03378331005" # Extra char
"AU0000XVGZA3"
"AU0000VXGZA3"
"FR0000988040"
"F00Ö00988040" # Illegal char
}
≡◇Valid Tests
</syntaxhighlight>
{{out}}
<pre>
[1 1 0 0 0 1 1 1 0]
</pre>
=={{header|VBScript}}==
<syntaxhighlight lang="vb">' Validate International Securities Identification Number - 03/03/2019
|