RosettaCodeData/Task/IBAN/11l/iban.11l
2023-07-01 13:44:08 -04:00

39 lines
2 KiB
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

F mod97(numberstring)
V segstart = 0
V step = 9
V prepended =
V number = 0
L segstart < numberstring.len - step
number = Int(prependednumberstring[segstart .< segstart + step])
V remainder = number % 97
prepended = String(remainder)
I remainder < 10
prepended = 0prepended
segstart += step
step = 7
number = Int(prependednumberstring[segstart ..])
R number % 97
V country2length = [IS = 26, IT = 27, MT = 31, MU = 30, MR = 27, MK = 19, IE = 22, MD = 24,
ME = 22, MC = 27, IL = 23, DE = 22, DO = 28, DK = 18, PK = 24, HR = 21,
HU = 28, FI = 18, LU = 20, LT = 20, LV = 21, KW = 30, LI = 21, PS = 29,
PT = 25, LB = 28, GB = 22, GE = 22, CR = 21, TR = 26, GI = 23, GL = 18,
CY = 28, CZ = 24, GR = 27, GT = 28, KZ = 20, TN = 24, CH = 21, SE = 24,
SA = 24, SM = 27, SI = 19, SK = 24, PL = 28, BR = 29, FR = 27, FO = 18,
BA = 20, BG = 22, BE = 16, BH = 22, VG = 24, RO = 24, RS = 22, NO = 15,
NL = 18, AZ = 28, EE = 20, AT = 20, ES = 24, AL = 28, AD = 24, AE = 23]
F valid_iban(iban_)
V iban = iban_.replace( , ).replace("\t", )
I !re:[\dA-Z]+.match(iban)
R 0B
I iban.len != :country2length[iban[0.<2]]
R 0B
iban = iban[4..]iban[0.<4]
R mod97(iban.map(ch -> String(Int(ch, radix' 36))).join()) == 1
L(account) [GB82 WEST 1234 5698 7654 32,
GB82 TEST 1234 5698 7654 32]
print(#. validation is: #..format(account, valid_iban(account)))