Anonymous user
ISBN13 check digit: Difference between revisions
m
→{{header|Haskell}}
No edit summary |
|||
Line 167:
</pre>
=={{header|Haskell}}==
<lang haskell>
import Data.Char (isDigit, digitToInt)
import Control.Monad (forM_)
Line 175 ⟶ 173:
testISBNs :: [String]
testISBNs = ["978-1734314502" , "978-1734314509", "978-1788399081", "978-1788399083"]
pair :: Num a => [a] -> [(a, a)]
pair [] = []
pair xs = p' (take 2 xs) : pair (drop 2 xs)
where p' ps = case ps of (x:y:zs) -> (x,y)
validIsbn13 :: String -> Bool
Line 187 ⟶ 186:
| otherwise = calc isbn `rem` 10 == 0
where digits = map digitToInt . filter isDigit
calc = foldl (\a
▲ then head b + (head $ reverse b) * 3 + a
main :: IO ()
Line 201 ⟶ 198:
978-1788399083: Valid: False
</pre>
=={{header|Julia}}==
<lang julia>function isbncheck(str)
|