How to resolve the algorithm CUSIP step by step in the CLU programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm CUSIP step by step in the CLU programming language

Table of Contents

Problem Statement

A   CUSIP   is a nine-character alphanumeric code that identifies a North American financial security for the purposes of facilitating clearing and settlement of trades. The CUSIP was adopted as an American National Standard under Accredited Standards X9.6.

Ensure the last digit   (i.e., the   check digit)   of the CUSIP code (the 1st column) is correct, against the following:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm CUSIP step by step in the CLU programming language

Source code in the clu programming language

valid_cusip = proc (s: string) returns (bool)
    own chars: string := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ*@#"
    if string$size(s) ~= 9 then return(false) end
    sum: int := 0
    for i: int in int$from_to(1,8) do
        v: int := string$indexc(s[i], chars)-1
        if v<0 then return(false) end
        if i//2=0 then v := v*2 end
        sum := sum + v/10 + v//10
    end
    check: int := (10 - sum // 10) // 10
    return(check = string$indexc(s[9], chars)-1)
end valid_cusip

start_up = proc ()
    po: stream := stream$primary_output()
    cusips: array[string] := array[string]$[
        "037833100",
        "17275R102",
        "38259P508",
        "594918104",
        "68389X106",
        "68389X105"
    ]
    
    for cusip: string in array[string]$elements(cusips) do
        stream$puts(po, cusip || ": ")
        if valid_cusip(cusip)
            then stream$putl(po, "valid")
            else stream$putl(po, "invalid")
        end 
    end
end start_up

  

You may also check:How to resolve the algorithm Rate counter step by step in the BBC BASIC programming language
You may also check:How to resolve the algorithm Pernicious numbers step by step in the VBScript programming language
You may also check:How to resolve the algorithm Substring step by step in the ARM Assembly programming language
You may also check:How to resolve the algorithm Polymorphism step by step in the Phix programming language
You may also check:How to resolve the algorithm Tic-tac-toe step by step in the Lasso programming language