Created
November 15, 2014 21:39
-
-
Save joom/8978347df6c471a534bb to your computer and use it in GitHub Desktop.
Republic of Turkey ID number validity checker
This file contains 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 Data.List (partition) | |
import Control.Arrow ((***)) | |
idValidate n = (length ds == 11) && check1 && check2 | |
where ds = map (\x -> read [x] :: Int) (show n) | |
(o, e) = map snd *** map snd $ partition (\(x,_)->odd x) $ zip [1..9] ds | |
check1 = ds !! 9 == (sum o * 7 - sum e) `mod` 10 | |
check2 = ds !! 10 == sum (init ds) `mod` 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment