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] -> String
checkSumFromSedolValues :: [Int] -> Int
checkSumFromSedolValues xs =
checkSumFromSedolValues xs =
show $
rem
rem
( 10
( 10
- rem
- rem
( sum $
( sum $
zipWith
zipWith
(*)
(*)
[1, 3, 1, 7, 3, 9]
[1, 3, 1, 7, 3, 9]
xs
xs
)
)
10
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 -------------------------