Dutch Burgerservicenummer (BSN) eleven-test
JavaScript (ES6) 57
Input as an array of chars. reduceRight
saves the day!
s=>!(i=1,t=s.reduceRight((t,v)=>t-v*++i),!t|t%11|(i|1)-9)
Test
F=
s=>!(i=1,t=s.reduceRight((t,v)=>t-v*++i),!t|t%11|(i|1)-9)
;['111222333','123456782','232262536','010464554','10464554','44016773']
.forEach(t=>{
var r=F([...t]);console.log(t,r)
})
;['000000000','192837465','247594057','88888888','73','3112223342','3112223342']
.forEach(t=>{
var r=F([...t]);console.log(t,r)
})
05AB1E, 23 21 bytes
`()DgLR*OD11Ö89¹gåP0Ê
Try it online! or as a Test suite
Explanation
` # push input as individual chars onto stack
( # negate top value
) # wrap in list
DgLR # range [len(input) ... 1]
*O # multiply with list of digits and sum
D11Ö # is evenly divisible by 11
89¹gå # len(input) is 8 or 9
P # product of sum/divisible by 11/len in (8,9)
0Ê # not equal to 0
R, 86 67 bytes
Edit: Thanks to Jarko Dubbeldam for suggesting the dot product!
l=length(x<-scan(,""));s=as.double(x)%*%c(l:2,-1);!s%%11&s&l>7&l<10
Reads input from stdin and store as an array/vector of characters. Subsequently convert to numeric,multiply with the vector 9...2,-1
and check all conditions.