How to resolve the algorithm CUSIP step by step in the Common Lisp programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm CUSIP step by step in the Common Lisp 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 Common Lisp programming language
Source code in the common programming language
(defun char->value (c)
(cond ((digit-char-p c 36))
((char= c #\*) 36)
((char= c #\@) 37)
((char= c #\#) 38)
(t (error "Invalid character: ~A" c))))
(defun cusip-p (cusip)
(and (= 9 (length cusip))
(loop for i from 1 to 8
for c across cusip
for v = (char->value c)
when (evenp i)
do (setf v (* 2 v))
sum (multiple-value-bind (quot rem) (floor v 10)
(+ quot rem))
into sum
finally (return (eql (digit-char-p (char cusip 8))
(mod (- 10 (mod sum 10)) 10))))))
(defun main ()
(dolist (cusip '("037833100" "17275R102" "38259P508" "594918104" "68389X106" "68389X105"))
(format t "~A: ~A~%" cusip (cusip-p cusip))))
You may also check:How to resolve the algorithm Return multiple values step by step in the Fōrmulæ programming language
You may also check:How to resolve the algorithm String concatenation step by step in the Oforth programming language
You may also check:How to resolve the algorithm Bitmap/Midpoint circle algorithm step by step in the OCaml programming language
You may also check:How to resolve the algorithm Roman numerals/Encode step by step in the Cowgol programming language
You may also check:How to resolve the algorithm Luhn test of credit card numbers step by step in the 360 Assembly programming language