Sha256: 667b840db4817fe3ae5b5b4d9ab59793168c6ba043805e9c969fce647b6318d3

Contents?: true

Size: 475 Bytes

Versions: 229

Compression:

Stored size: 475 Bytes

Contents

module Luhn (isValid) where

import Data.Char (digitToInt)

luhnDouble :: Integral a => a -> a
luhnDouble n | n < 5     = n * 2
             | otherwise = n * 2 - 9

luhnDigits :: Integral a => [a] -> [a]
luhnDigits = zipWith ($) (cycle [id, luhnDouble]) . reverse

checksum :: Integral a => [a] -> a
checksum = (`rem` 10) . sum . luhnDigits

isValid :: String -> Bool
isValid s = length digits > 1 && checksum digits == 0
  where digits = map digitToInt $ filter (/= ' ') s

Version data entries

229 entries across 229 versions & 1 rubygems

Version Path
trackler-2.2.0.5 tracks/haskell/exercises/luhn/examples/success-standard/src/Luhn.hs
trackler-2.2.0.4 tracks/haskell/exercises/luhn/examples/success-standard/src/Luhn.hs
trackler-2.2.0.3 tracks/haskell/exercises/luhn/examples/success-standard/src/Luhn.hs
trackler-2.2.0.2 tracks/haskell/exercises/luhn/examples/success-standard/src/Luhn.hs
trackler-2.2.0.1 tracks/haskell/exercises/luhn/examples/success-standard/src/Luhn.hs
trackler-2.2.0.0 tracks/haskell/exercises/luhn/examples/success-standard/src/Luhn.hs
trackler-2.1.0.55 tracks/haskell/exercises/luhn/examples/success-standard/src/Luhn.hs
trackler-2.1.0.54 tracks/haskell/exercises/luhn/examples/success-standard/src/Luhn.hs
trackler-2.1.0.53 tracks/haskell/exercises/luhn/examples/success-standard/src/Luhn.hs
trackler-2.1.0.52 tracks/haskell/exercises/luhn/examples/success-standard/src/Luhn.hs
trackler-2.1.0.51 tracks/haskell/exercises/luhn/examples/success-standard/src/Luhn.hs
trackler-2.1.0.50 tracks/haskell/exercises/luhn/examples/success-standard/src/Luhn.hs
trackler-2.1.0.49 tracks/haskell/exercises/luhn/examples/success-standard/src/Luhn.hs
trackler-2.1.0.48 tracks/haskell/exercises/luhn/examples/success-standard/src/Luhn.hs
trackler-2.1.0.47 tracks/haskell/exercises/luhn/examples/success-standard/src/Luhn.hs
trackler-2.1.0.46 tracks/haskell/exercises/luhn/examples/success-standard/src/Luhn.hs
trackler-2.1.0.45 tracks/haskell/exercises/luhn/examples/success-standard/src/Luhn.hs
trackler-2.1.0.44 tracks/haskell/exercises/luhn/examples/success-standard/src/Luhn.hs
trackler-2.1.0.43 tracks/haskell/exercises/luhn/examples/success-standard/src/Luhn.hs
trackler-2.1.0.42 tracks/haskell/exercises/luhn/examples/success-standard/src/Luhn.hs