How to resolve the algorithm SEDOLs step by step in the Fortran programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm SEDOLs step by step in the Fortran programming language
Table of Contents
Problem Statement
For each number list of 6-digit SEDOLs, calculate and append the checksum digit.
That is, given this input: Produce this output: Check each input is correctly formed, especially with respect to valid characters allowed in a SEDOL string.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm SEDOLs step by step in the Fortran programming language
Source code in the fortran programming language
MODULE SEDOL_CHECK
IMPLICIT NONE
CONTAINS
FUNCTION Checkdigit(c)
CHARACTER :: Checkdigit
CHARACTER(6), INTENT(IN) :: c
CHARACTER(36) :: alpha = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
INTEGER, DIMENSION(6) :: weights = (/ 1, 3, 1, 7, 3, 9 /), temp
INTEGER :: i, n
DO i = 1, 6
temp(i) = INDEX(alpha, c(i:i)) - 1
END DO
temp = temp * weights
n = MOD(10 - (MOD(SUM(temp), 10)), 10)
Checkdigit = ACHAR(n + 48)
END FUNCTION Checkdigit
END MODULE SEDOL_CHECK
PROGRAM SEDOLTEST
USE SEDOL_CHECK
IMPLICIT NONE
CHARACTER(31) :: valid = "0123456789BCDFGHJKLMNPQRSTVWXYZ"
CHARACTER(6) :: codes(10) = (/ "710889", "B0YBKJ", "406566", "B0YBLH", "228276" , &
"B0YBKL", "557910", "B0YBKR", "585284", "B0YBKT" /)
CHARACTER(7) :: sedol
INTEGER :: i, invalid
DO i = 1, 10
invalid = VERIFY(codes(i), valid)
IF (invalid == 0) THEN
sedol = codes(i)
sedol(7:7) = Checkdigit(codes(i))
ELSE
sedol = "INVALID"
END IF
WRITE(*, "(2A9)") codes(i), sedol
END DO
END PROGRAM SEDOLTEST
You may also check:How to resolve the algorithm Cheryl's birthday step by step in the Sidef programming language
You may also check:How to resolve the algorithm Cumulative standard deviation step by step in the Clojure programming language
You may also check:How to resolve the algorithm Look-and-say sequence step by step in the 8086 Assembly programming language
You may also check:How to resolve the algorithm Averages/Mode step by step in the Smalltalk programming language
You may also check:How to resolve the algorithm Total circles area step by step in the Python programming language