Validate International Securities Identification Number: Difference between revisions

(→‎{{header|Raku}}: fix up internal link)
Line 1,584:
The luhn test is repeated here for simplicity (from Luhn_test_of_credit_card_numbers#langur).
 
{{works with|langur|0.68.1110}}
<lang langur>val .luhntest = f(.s) {
val .t = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]
val .numbers = map f .c-'0', s2cps2n .s
val .oddeven = len(.numbers) rem 2
 
for[=0] .i of .numbers, {
foldfrom(
f(.sum,_for .i, .c)+= if (.i rem 2 == .oddeven {: .sum + numbers[.c } else { .sum +i]; .t[.cnumbers[.i]+1] },)
} rem 10 == 0,
series len .numbers,
.numbers,
) rem 10 == 0
}
 
val .isintest = f(.s) {
if not matching(re/^[A-Z][A-Z][0-9A-Z]{9}[0-9]$/, .s) {and
return.luhntest(join falses2n .s)
}
.luhntest(join map f toNumber(.c, 36), split .s)
 
# used unbounded lists on join(), map(), and split()...
# ... and implied parameters and a single expression on the anonymous function
# same as .luhntest(join(map(f(.c) { toNumber(.c, 36) }, split(.s))))
}
 
885

edits