How to resolve the algorithm Validate International Securities Identification Number step by step in the Perl 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 Perl 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 Perl programming language
Source code in the perl programming language
use strict;
use English;
use POSIX;
use Test::Simple tests => 7;
ok( validate_isin('US0378331005'), 'Test 1');
ok( ! validate_isin('US0373831005'), 'Test 2');
ok( ! validate_isin('U50378331005'), 'Test 3');
ok( ! validate_isin('US03378331005'), 'Test 4');
ok( validate_isin('AU0000XVGZA3'), 'Test 5');
ok( validate_isin('AU0000VXGZA3'), 'Test 6');
ok( validate_isin('FR0000988040'), 'Test 7');
exit 0;
sub validate_isin {
my $isin = shift;
$isin =~ /\A[A-Z]{2}[A-Z\d]{9}\d\z/s or return 0;
my $base10 = join(q{}, map {scalar(POSIX::strtol($ARG, 36))}
split(//s, $isin));
return luhn_test($base10);
}
You may also check:How to resolve the algorithm Semordnilap step by step in the Transd programming language
You may also check:How to resolve the algorithm Faulhaber's formula step by step in the GAP programming language
You may also check:How to resolve the algorithm Send an unknown method call step by step in the Lasso programming language
You may also check:How to resolve the algorithm Primality by trial division step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Sort an integer array step by step in the Frink programming language