dt  =: +/"1 ]10 10 #: (8$1 2) */ i.#cn
ct  =: 101 $ '0987654321'
ccd5=: ct {~ [: +/ dt {"_1~ cn i. i.@<:@[EMAIL PROTECTED] |: ]

   x=: cn {~ 100 1000 8 [EMAIL PROTECTED] #cn
   (ccd"1 -: ccd5) x
1



----- Original Message -----
From: Dan Bron <[EMAIL PROTECTED]>
Date: Sunday, August 3, 2008 8:20
Subject: [Jprogramming] CUSIP (was: Check digit utility)
To: Programming forum <[email protected]>

> Alright, now that we've got SEDOLs down, let's bring the problem 
> across the pond.  
> 
> A CUSIP is the North American analog of the SEDOL.  Its 
> format is described at [1].  Provide a verb which, given 
> the first 8 digits of a CUSIP, produces the check digit.  
> The usual metrics apply:  novelty, brevity, velocity, and 
> parsimony.
> To get you started, here's an rough first draft:
> 
>            
> cn  =.  '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
>            ccd 
> =:  (10 | 10 - [: +/@:, 10 #.^:_1 ] * 1 + 2 | 
> [EMAIL PROTECTED])&.(cn&i.)   NB.  CUSIP check digit
>            
>            ccd 
> }: '931142103'  
>       3
>            
>            ({: 
> -: ccd@:}:) '931142103'
>       1
> 
> -Dan
> 
> [1]  http://en.wikipedia.org/wiki/CUSIP
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to