A Dutch BSN (BurgerServiceNummer) is valid when it complies to the following rules:
- It only contains digits.
- The length should be either 8 or 9 in length.
- When the digits are indexed as
I, the result of the following sum:
9xA + 8xB + 7xC + 6xD + 5xE + 4xF + 3xG + 2xH + -1xI(NOTE the -1 instead of 1!) should be divisible by 11, and should not be 0.
Input: A string or char-array representing the BSN.
Output: A truthy or falsey result whether the input is a valid BSN.
- The input format should be a string or char-array. You are not allowed to use an int-array of digits, or a (possibly octal) number. (You are allowed to convert it to an int-array of digits yourself, though, but not directly as argument.)
- Despite the restriction on the input above, you can assume all test cases will contain one or more digits (
- Regarding the BSN with length 8 instead of 9, the Dutch Wikipedia states the following: "For the eleven-test and for other practical uses, a leading zero is added to make the number of length 9." (source)
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
- Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code.
- Also, please add an explanation if necessary.
// Truthy test cases: 111222333 123456782 232262536 010464554 10464554 44016773 // Falsey test cases: 000000000 192837465 247594057 88888888 73 3112223342 000000012