Created
January 14, 2015 18:49
-
-
Save itarato/eeec9f46bee9960bd503 to your computer and use it in GitHub Desktop.
Challenge 197 easy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validISBN x y | |
| x > 9 = validISBN (reduce (fromIntegral x)) (extra (fromIntegral x) y) | |
| otherwise = elevens (fromIntegral x) y | |
reduce x = round(x) `mod` (tens x) | |
lvl x = floor $ logBase 10 x | |
extra x y = y + ((round(x) `div` (tens x)) * ((lvl x) + 1)) | |
tens x = round(10 ^^ (lvl x)) | |
elevens x y = ((round(x) + y) `mod` 11) == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment