Validate International Securities Identification Number: Difference between revisions
Content added Content deleted
(→{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details) |
No edit summary |
||
Line 998: | Line 998: | ||
FR0000988040 True |
FR0000988040 True |
||
</pre> |
</pre> |
||
=={{header|PureBasic}}== |
|||
<lang PureBasic>EnableExplicit |
|||
Procedure.i Check_ISIN(*c.Character) |
|||
Define count.i=0, Idx.i=1, v.i=0, i.i |
|||
Dim s.i(24) |
|||
If MemoryStringLength(*c) > 12 : ProcedureReturn #False : EndIf |
|||
While *c\c |
|||
count+1 |
|||
If *c\c>='0' And *c\c<='9' |
|||
If count<=2 : ProcedureReturn #False : EndIf |
|||
s(Idx)= *c\c - '0' |
|||
Idx+1 |
|||
ElseIf *c\c>='A' And *c\c<='Z' |
|||
s(Idx)= (*c\c - ('A'-10)) / 10 |
|||
Idx+1 |
|||
s(Idx)= (*c\c - ('A'-10)) % 10 |
|||
Idx+1 |
|||
Else |
|||
ProcedureReturn #False |
|||
EndIf |
|||
*c + SizeOf(Character) |
|||
Wend |
|||
For i=Idx-2 To 0 Step -2 |
|||
If s(i)*2 > 9 |
|||
v+ s(i)*2 -9 |
|||
Else |
|||
v+ s(i)*2 |
|||
EndIf |
|||
v+s(i+1) |
|||
Next |
|||
ProcedureReturn Bool(v%10=0) |
|||
EndProcedure |
|||
Define.s s |
|||
OpenConsole("Validate_International_Securities_Identification_Number (ISIN)") |
|||
If ReadFile(0,"c:\code_pb\rosettacode\data\isin.txt") |
|||
While Not Eof(0) |
|||
s=ReadString(0) |
|||
Print(s+~"\t") |
|||
If Check_ISIN(@s) : PrintN("TRUE") : Else : PrintN("FALSE") : EndIf |
|||
Wend |
|||
CloseFile(0) |
|||
EndIf |
|||
Input()</lang> |
|||
{{Out}} |
|||
<pre>US0378331005 TRUE |
|||
US0373831005 FALSE |
|||
U50378331005 FALSE |
|||
US03378331005 FALSE |
|||
AU0000XVGZA3 TRUE |
|||
AU0000VXGZA3 TRUE |
|||
FR0000988040 TRUE</pre> |
|||
=={{header|Python}}== |
=={{header|Python}}== |