Last active
November 13, 2015 05:06
-
-
Save lotz84/333d1ebc9153a703cac6 to your computer and use it in GitHub Desktop.
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
import GHC.Int | |
validateMyNumber :: Int64 -> Bool | |
validateMyNumber myNumber | |
| length (show myNumber) <= 12 = | |
let (x:pn) = take 12 . map (`mod` 10) . iterate (`div` 10) $ myNumber | |
qn = [if n <= 6 then n + 1 else n - 5 | n <- [1..11]] | |
y = (`mod` 11) . sum . zipWith (*) qn $ pn | |
in x == if y <= 1 then 0 else (11 - y) | |
| otherwise = False | |
main :: IO () | |
main = do | |
print $ validateMyNumber 123456789010 -- False | |
print $ validateMyNumber 123456789011 -- False | |
print $ validateMyNumber 123456789012 -- False | |
print $ validateMyNumber 123456789013 -- False | |
print $ validateMyNumber 123456789014 -- False | |
print $ validateMyNumber 123456789015 -- False | |
print $ validateMyNumber 123456789016 -- False | |
print $ validateMyNumber 123456789017 -- False | |
print $ validateMyNumber 123456789018 -- True | |
print $ validateMyNumber 123456789019 -- False | |
print $ validateMyNumber 023456789013 -- True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment