Validate International Securities Identification Number: Difference between revisions
Validate International Securities Identification Number (view source)
Revision as of 08:24, 31 May 2017
, 7 years ago→{{header|Haskell}}: (tidied isinPattern)
(→{{header|Haskell}}: Tidied character type pattern check (isinPattern)) |
(→{{header|Haskell}}: (tidied isinPattern)) |
||
Line 926:
validISIN = liftM2 (&&) isinPattern (luhn . (show =<<) . stringInts)
isinPattern
12 == length s &&
]▼
luhn x =
Line 941 ⟶ 939:
s2 = sum $ sum . stringInts . show . (2 *) <$> stream even
in rem (s1 + s2) 10 == 0
capitals, digits :: String▼
capitals = ['A' .. 'Z']▼
digits = ['0' .. '9']▼
charMap :: M.Map Char Int
Line 952 ⟶ 945:
stringInts :: String -> [Int]
stringInts = fromMaybe [] . sequence . fmap (`M.lookup` charMap)
bites :: [Int] -> [a] -> [[a]]
bites ns xs =
reverse . fst $
foldr
(\x (a, r) ->
let (b, r_) = splitAt x r
in (b : a, r_))
▲ ([], xs)
(reverse ns)
▲capitals, digits :: String
▲capitals = ['A' .. 'Z']
▲digits = ['0' .. '9']
main :: IO ()
|