Validate International Securities Identification Number: Difference between revisions
Validate International Securities Identification Number (view source)
Revision as of 11:28, 15 June 2020
, 3 years ago→{{header|Haskell}}: Tidied the second variant
Catskill549 (talk | contribs) |
(→{{header|Haskell}}: Tidied the second variant) |
||
Line 1,451:
FR0000988040 is valid</pre>
Or, making alternative choices from the standard libraries:
<lang haskell>import qualified Data.Map as M
import Data.Bifunctor (first)
import Data.Maybe (fromMaybe)
validISIN, isinPattern, luhn :: String -> Bool
validISIN = (&&)
isinPattern s =
12 == length s &&
let [l, m, r] = bites [2, 9, 1] s▼
where
▲ all (`elem` (capitals ++ digits)) m && head r `elem` digits
luhn x = 0 == rem (s1 + s2) 10
where
odds =
stream f = concat $ zipWith ($) (cycle f) (stringInts $ reverse x)
charMap :: M.Map Char Int
Line 1,476 ⟶ 1,478:
stringInts :: String -> [Int]
stringInts = fromMaybe [] .
bites :: [Int] -> [a] -> [[a]]
bites ns xs =
(reverse . fst) $
foldr (\x (a, r) -> first (: a) (splitAt x r)) ([], xs) (reverse ns)
capitals, digits :: String
|