SEDOLs: Difference between revisions
Content added Content deleted
(→{{header|Haskell}}: Added test case and output for ill-formed sedol string.) |
|||
Line 1,636: | Line 1,636: | ||
checkSum x = |
checkSum x = |
||
case traverse sedolValue x of |
case traverse sedolValue x of |
||
Right xs -> checkSumFromSedolValues xs |
Right xs -> (show . checkSumFromSedolValues) xs |
||
Left annotated -> annotated |
Left annotated -> annotated |
||
checkSumFromSedolValues :: [Int] -> |
checkSumFromSedolValues :: [Int] -> Int |
||
checkSumFromSedolValues xs = |
checkSumFromSedolValues xs = |
||
rem |
|||
( 10 |
|||
- rem |
|||
( sum $ |
|||
zipWith |
|||
(*) |
|||
[1, 3, 1, 7, 3, 9] |
|||
xs |
|||
) |
|||
10 |
|||
) |
|||
10 |
|||
10 |
|||
sedolValue :: Char -> Either String Int |
sedolValue :: Char -> Either String Int |
||
Line 1,660: | Line 1,659: | ||
| isDigit c = Right (ord c - ord '0') |
| isDigit c = Right (ord c - ord '0') |
||
| isAsciiUpper c = Right (ord c - ord 'A' + 10) |
| isAsciiUpper c = Right (ord c - ord 'A' + 10) |
||
--------------------------- TEST ------------------------- |
--------------------------- TEST ------------------------- |