Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
|
|
@ -1,23 +1,23 @@
|
|||
val .luhntest = fn(.s) {
|
||||
val .t = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]
|
||||
val .numbers = s2n .s
|
||||
val .oddeven = len(.numbers) rem 2
|
||||
val luhntest = fn(s) {
|
||||
val t = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]
|
||||
val numbers = s -> s2n
|
||||
val oddeven = len(numbers) rem 2
|
||||
|
||||
for[=0] .i of .numbers {
|
||||
_for += if .i rem 2 == .oddeven {
|
||||
.numbers[.i]
|
||||
for[=0] i of numbers {
|
||||
_for += if i rem 2 == oddeven {
|
||||
numbers[i]
|
||||
} else {
|
||||
.t[.numbers[.i]+1]
|
||||
t[numbers[i]+1]
|
||||
}
|
||||
} div 10
|
||||
}
|
||||
|
||||
val .isintest = fn(.s) {
|
||||
.s -> re/^[A-Z][A-Z][0-9A-Z]{9}[0-9]$/ and
|
||||
.luhntest(join s2n .s)
|
||||
val isintest = fn(s) {
|
||||
s -> re/^[A-Z][A-Z][0-9A-Z]{9}[0-9]$/ and
|
||||
s -> s2n -> join -> luhntest
|
||||
}
|
||||
|
||||
val .tests = h{
|
||||
val tests = {
|
||||
"US0378331005": true,
|
||||
"US0373831005": false,
|
||||
"U50378331005": false,
|
||||
|
|
@ -27,8 +27,8 @@ val .tests = h{
|
|||
"US03378331005": false,
|
||||
}
|
||||
|
||||
for .key in sort(keys .tests) {
|
||||
val .pass = .isintest(.key)
|
||||
write .key, ": ", .pass
|
||||
writeln if(.pass == .tests[.key]: ""; " (ISIN TEST FAILED)")
|
||||
for key in sort(keys(tests)) {
|
||||
val pass = isintest(key)
|
||||
write key, ": ", pass
|
||||
writeln if(pass == tests[key]: ""; " (ISIN TEST FAILED)")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,43 @@
|
|||
/*REXX program validates the checksum digit for an International Securities ID number.*/
|
||||
parse arg z /*obtain optional ISINs from the C.L.*/
|
||||
if z='' then z= "US0378331005 US0373831005 U50378331005 US03378331005 AU0000XVGZA3" ,
|
||||
'AU0000VXGZA3 FR0000988040' /* [↑] use the default list of ISINs.*/
|
||||
/* [↓] process all specified ISINs.*/
|
||||
do n=1 for words(z); x=word(z, n); y= x /*obtain an ISIN from the Z list. */
|
||||
$= /* [↓] construct list of ISIN digits. */
|
||||
do k=1 for length(x); _= substr(x,k,1) /*the ISIN may contain alphabetic chars*/
|
||||
p= pos(_, 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ) /*X must contain A──►Z, 0──►9.*/
|
||||
if p==0 then y= /*trigger "not" valid below.*/
|
||||
else $= $ || p-1 /*convert X string (base 36 ──► dec).*/
|
||||
end /*k*/ /* [↑] convert alphabetic ──► digits.*/
|
||||
@= /*placeholder for the "not" in message.*/
|
||||
if length(y)\==12 then @= "not" /*see if the ISIN is exactly 12 chars. */
|
||||
if \datatype( left(x,2),'U') then @= "not" /* " " " " 1st 2 chars cap. let.*/
|
||||
if \datatype(right(x,1),'W') then @= "not" /* " " " " last char not a digit*/
|
||||
if @=='' then if \luhn($) then @= "not" /* " " " " passed the Luhn test.*/
|
||||
say right(x, 30) right(@, 5) "valid" /*display the yea or nay message.*/
|
||||
end /*n*/ /* [↑] 1st 3 IFs could've been combined*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
Luhn: procedure; parse arg x; $= 0 /*get credit card number; zero $ 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)
|
||||
$= $ + substr(y, j, 1) + left(_, 1) + substr(_, 2 , 1, 0)
|
||||
end /*j*/ /* [↑] sum the odd and even digits.*/
|
||||
return right($, 1)==0 /*return "1" if number passed Luhn test*/
|
||||
/*REXX program validates International Securities ID numbers. */
|
||||
Parse Arg z /*obtain ISINs from the C.L. */
|
||||
If z='' Then /* [?] use the default list of ISINs */
|
||||
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) /*obtain an ISIN from the Z list. */
|
||||
p=verify(x,valid,'N')
|
||||
If p>0 Then msg='invalid character in position' p':' substr(x,p,1)
|
||||
Else Do
|
||||
dd='' /* [?] construct list of ISIN digits. */
|
||||
Do k=1 To length(x)
|
||||
_=substr(x,k,1) /*the ISIN may contain alphabetic chars*/
|
||||
p=pos(_,valid) /*X contains 0-->9 A-->Z */
|
||||
dd=dd||p-1 /*convert X string (base 36 --? dec).*/
|
||||
End
|
||||
msg=''
|
||||
Select
|
||||
When length(x)\==12 Then msg='not exactly 12 chars'
|
||||
When \datatype( left(x,2),'U') Then msg='not starting with 2 capital chars'
|
||||
When \datatype(right(x,1),'W') Then msg='last character is not a digit'
|
||||
Otherwise
|
||||
If \luhn(dd) Then msg='does not pass the Luhn test'
|
||||
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 */
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue