Created
June 10, 2011 12:44
-
-
Save barend/1018771 to your computer and use it in GitHub Desktop.
Burgerservicenummer Elfproef Validator
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
/** Validate BSN according to http://nl.wikipedia.org/wiki/Burgerservicenummer */ | |
private boolean isValidBSN(int candidate) { | |
if (candidate <= 9999999 || candidate > 999999999) { | |
return false; | |
} | |
int sum = -1 * candidate % 10; | |
for (int multiplier = 2; candidate > 0; multiplier++) { | |
int val = (candidate /= 10) % 10; | |
sum += multiplier * val; | |
} | |
return sum != 0 && sum % 11 == 0; | |
} |
Interesting that you started with 100000000, because the first years (everyone that transferred from the old system) these numbers had 8 digits. Those numbers got a leading zero when the length of the number was increased to 9 digits.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, I was making this code as well, and found your example code to be helpfull, thanks!
If someone else stumbles upon this, looking to use it here is my implementation of this code, it is a bit faster(19.5s > 16.3s for the first 2m numbers), but could be improved by multithreading if you'd realy want.
As i fed everyting from 100000000 to 999999999 i left out the first check.
(ignore the line with MD5, that was used for my implementation, you could change the type to boolean and return true there)
Thanks, your code was much appreciated