Initiated due to a collaboration with Camillus on a bookmarklet which involved mapping NUSNET IDs to matriculation numbers for use with a [redacted] endpoint – I initially helped with the U prefix case, as it is more familiar to old farts like me.
Various equivalent forms of the algorithm have been discussed under NUS Matriculation Number Checkdigit, NUS Matriculation Number Checkdigit 2 and Validate Your NUS Undergraduate Matric Number. Also, there is a server-side NUS Matric Resolver by Huy Nguyen and a Matric.js gist by Joel Low.
Though correct, most of them involve extraneous steps, especially for U-prefixed matriculation numbers. It kinda bugged me, so I worked out a more elegant formulation during a short plane ride last week.
For U-prefixed NUSNET IDs such as
u0906931, discard the third digit – u09
06931, resulting in
u096931, which is the corresponding matriculation number without its check digit.
Let the last 6 digits be d1 to d6. Compute the weighted sum s = w1 × d1 + … + w6 × d6 using the corresponding weights:
Prefix w1 w2 w3 w4 w5 w6 U 0 1 3 1 2 7 A 1 1 1 1 1 1
Find check digit corresponding to the remainder of the weighted sum divided by 13 (sum modulo 13):
Remainder 0 1 2 3 4 5 6 7 8 9 10 11 12 Check Digit Y X W U R N M L J H E A B
The weights for A-prefixed matriculation numbers are all 1, i.e. the weighted sum is simply equal to the sum of the digits themselves, so their specific algorithm could be simplified further. However, it is formulated like this to unify the algorithms for both current prefixes, as well as possibly accommodate future prefixes with different weights.
If this scheme and blog post are somehow still surviving in the far future, you would have to use all 7 digits instead of the last 6, when there have been over 1 million NUS undergraduates since 2010.
Historical note: The U prefix applied to undergraduates from AY2009/10 and before; the A prefix applies to undergraduates from AY2010/11 and after.
Matriculation Number Calculator
Could come in handy for quickly finding project mates’ matriculation numbers.