Skip to content

Instantly share code, notes, and snippets.

@azakordonets
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save azakordonets/282da23a957650f89b70 to your computer and use it in GitHub Desktop.

Select an option

Save azakordonets/282da23a957650f89b70 to your computer and use it in GitHub Desktop.
/** Validate BSN according to http://nl.wikipedia.org/wiki/Burgerservicenummer */
private def isValidBSN(candidate: Int): Boolean = {
var bsn = candidate
if (bsn <= 9999999 || bsn > 999999999) {
return false;
}
var sum: Int = -1 * bsn % 10;
for (multiplier <- 2 to 1000 ; if bsn > 0) {
bsn = bsn / 10
var value = bsn % 10
sum = sum + (multiplier * value)
}
return sum != 0 && sum % 11 == 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment