Validate International Securities Identification Number: Difference between revisions

→‎{{header|Haskell}}: A more legibile Luhn test
m (→‎{{header|Haskell}}: (edited out a duplication))
(→‎{{header|Haskell}}: A more legibile Luhn test)
Line 919:
 
Or, making alternative choices from standard libraries:
<lang haskell>import qualified Data.Map asChar M(digitToInt)
 
import qualified Data.Map as M
import Control.Monad (sequence, liftM2)
import Data.Maybe (fromMaybe)
Line 932 ⟶ 934:
elem (last isin) digits
 
luhn x =
let odd = [(: []), const []]
(0 ==) .
even = reverse odd
(`rem` 10) .
stream f = concat $ zipWith ($) (cycle f) (stringInts $ reverse x)
sum .
s1 = sum (stream odd)
fmap (uncurry (+) . (`quotRem` 10)) .
zipWith id (cycle [id, (2s2 *)])= sum $ sum . stringInts . reverseshow . (2 *) <$> stream even
in rem (s1 + s2) 10 == 0
 
capitals, digits :: String
9,659

edits