How to resolve the algorithm Validate International Securities Identification Number step by step in the 11l 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 11l 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 11l programming language

Source code in the 11l programming language

F check_isin(a)
   I a.len != 12
      R 0B
   [Int] s
   L(c) a
      I c.is_digit()
         I L.index < 2
            R 0B
         s.append(c.code - 48)
      E I c.is_uppercase()
         I L.index == 11
            R 0B
         V (d, m) = divmod(c.code - 55, 10)
         s [+]= [d, m]
      E
         R 0B
   V v = sum(s[((len)-1..).step(-2)])
   L(=k) s[((len)-2..).step(-2)]
      k = 2 * k
      v += I k > 9 {k - 9} E k
   R v % 10 == 0

print([‘US0378331005’, ‘US0373831005’, ‘U50378331005’, ‘US03378331005’,
       ‘AU0000XVGZA3’, ‘AU0000VXGZA3’, ‘FR0000988040’].map(s -> check_isin(s)))

  

You may also check:How to resolve the algorithm Loops/For with a specified step step by step in the Erlang programming language
You may also check:How to resolve the algorithm Chinese zodiac step by step in the Pascal programming language
You may also check:How to resolve the algorithm Gray code step by step in the Raku programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the Integer BASIC programming language
You may also check:How to resolve the algorithm Execute Brain step by step in the OCaml programming language