Last active
August 29, 2015 14:08
-
-
Save azakordonets/282da23a957650f89b70 to your computer and use it in GitHub Desktop.
/** Validate BSN according to http://nl.wikipedia.org/wiki/Burgerservicenummer */
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
| 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