Skip to content

Instantly share code, notes, and snippets.

@itarato
Created January 14, 2015 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itarato/eeec9f46bee9960bd503 to your computer and use it in GitHub Desktop.
Save itarato/eeec9f46bee9960bd503 to your computer and use it in GitHub Desktop.
Challenge 197 easy
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