Skip to content

Instantly share code, notes, and snippets.

@joom
Created November 15, 2014 21:39
Show Gist options
  • Save joom/8978347df6c471a534bb to your computer and use it in GitHub Desktop.
Save joom/8978347df6c471a534bb to your computer and use it in GitHub Desktop.
Republic of Turkey ID number validity checker
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