Created
March 13, 2017 19:48
-
-
Save pawelniewie/9801b696ad0d976130cd3d4f58111b92 to your computer and use it in GitHub Desktop.
Simple PESEL validator
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
def valid_pesel?(pesel) | |
false if pesel.size != 11 | |
(a, b, c, d, e, f, g, h, i, j, k) = pesel.chars.map(&:to_i) | |
checksum = a + 3*b + 7*c + 9*d + e + 3*f + 7*g + 9*h + i + 3*j + k | |
checksum % 10 == 0 | |
end | |
no = gets.to_i | |
no.times do | |
pesel = gets | |
puts valid_pesel?(pesel) ? 'Y' : 'N' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment