Skip to content

Instantly share code, notes, and snippets.

@pawelniewie
Created March 13, 2017 19:48
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 pawelniewie/9801b696ad0d976130cd3d4f58111b92 to your computer and use it in GitHub Desktop.
Save pawelniewie/9801b696ad0d976130cd3d4f58111b92 to your computer and use it in GitHub Desktop.
Simple PESEL validator
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