Validate International Securities Identification Number: Difference between revisions

(→‎{{header|REXX}}: improved and made ooRexx compatible)
 
(4 intermediate revisions by 2 users not shown)
Line 2,104:
The luhn test is repeated here for simplicity.
 
<syntaxhighlight lang="langur">val .luhntest = fn(.s) {
val luhntest = fn(s) {
val .t = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]
val .numberst = s2n[0, .s2, 4, 6, 8, 1, 3, 5, 7, 9]
val .oddevennumbers = len(.numbers)s rem-> 2s2n
val oddeven = len(numbers) rem 2
 
for[=0] .i of .numbers {
_for += if .i rem 2 == .oddeven {
.numbers[.i]
} else {
.t[.numbers[.i]+1]
}
} div 10
}
 
val .isintest = fn(.s) {
.s -> re/^[A-Z][A-Z][0-9A-Z]{9}[0-9]$/ and
.luhntest(joins -> s2n .s)-> join -> luhntest
}
 
val .tests = {
"US0378331005": true,
"US0373831005": false,
Line 2,133 ⟶ 2,134:
}
 
for .key in sort(keys .(tests)) {
val .pass = .isintest(.key)
write .key, ": ", .pass
writeln if(.pass == .tests[.key]: ""; " (ISIN TEST FAILED)")
}
}</syntaxhighlight>
 
{{out}}
Line 2,702 ⟶ 2,704:
 
=={{header|REXX}}==
<syntaxhighlight lang="rexx"></syntaxhighlight>
/*REXX program validates International Securities ID numbers. */
Parse Arg z /*obtain ISINs from the C.L. */
Line 2,745 ⟶ 2,747:
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=&nbsp; when using the default inputs:}}
<pre>
Line 3,289 ⟶ 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
1,007

edits