Skip to content

Instantly share code, notes, and snippets.

@barend
Created June 10, 2011 12:44
Show Gist options
  • Save barend/1018771 to your computer and use it in GitHub Desktop.
Save barend/1018771 to your computer and use it in GitHub Desktop.
Burgerservicenummer Elfproef Validator
/** 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;
}
@wds444
Copy link

wds444 commented Feb 5, 2018

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.

private static void test11(int b) {
		int ans =0;
		for(int i=9;i>1;i--) {
			ans +=ComputeDigitAt(b,i);
		}
		ans +=(b/Math.pow(10, 0)%10) * -1;
		if(ans% 11==0) {
			System.out.println(b + " : " + MD5(b));
		}
	}
`private static int ComputeDigitAt(int num, int n) {
	return (int)((num / Math.pow(10, n-1)) % 10)*n;
}`

(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

@VosWouter87
Copy link

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