How to resolve the algorithm Validate International Securities Identification Number step by step in the langur programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Validate International Securities Identification Number step by step in the langur programming language

Table of Contents

Problem Statement

An International Securities Identification Number (ISIN) is a unique international identifier for a financial security such as a stock or bond.

Write a function or program that takes a string as input, and checks whether it is a valid ISIN. It is only valid if it has the correct format,   and   the embedded checksum is correct. Demonstrate that your code passes the test-cases listed below.

The format of an ISIN is as follows:

For this task, you may assume that any 2-character alphabetic sequence is a valid country code. The checksum can be validated as follows:

(The comments are just informational.   Your function should simply return a Boolean result.   See #Raku for a reference solution.)

Related task:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Validate International Securities Identification Number step by step in the langur programming language

Source code in the langur programming language

val .luhntest = f(.s) {
    val .t = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]
    val .numbers = s2n .s
    val .oddeven = len(.numbers) rem 2

    for[=0] .i of .numbers {
        _for += if(.i rem 2 == .oddeven: .numbers[.i]; .t[.numbers[.i]+1])
    } div 10
}

val .isintest = f(.s) {
    matching(re/^[A-Z][A-Z][0-9A-Z]{9}[0-9]$/, .s) and
        .luhntest(join s2n .s)
}

val .tests = h{
    "US0378331005":  true,
    "US0373831005": false,
    "U50378331005": false,
    "AU0000XVGZA3": true,
    "AU0000VXGZA3": true,
    "FR0000988040": true,
    "US03378331005": false,
}

for .key in sort(keys .tests) {
    val .pass = .isintest(.key)
    write .key, ": ", .pass
    writeln if(.pass == .tests[.key]: ""; " (ISIN TEST FAILED)")
}

  

You may also check:How to resolve the algorithm Loops/For step by step in the Clojure programming language
You may also check:How to resolve the algorithm Galton box animation step by step in the Lua programming language
You may also check:How to resolve the algorithm Mertens function step by step in the SETL programming language
You may also check:How to resolve the algorithm Digital root/Multiplicative digital root step by step in the Factor programming language
You may also check:How to resolve the algorithm Abstract type step by step in the Seed7 programming language