The input is a 19-character string with digits and X for unknown digits. Its format is DDMMYYYY, followed by 10 arbitrary digits and a check digit K.
For the first 18 digits, the weights are 10 down to 2, repeated twice. Let S be their weighted sum modulo 19. Then K is S if S is at most 9, otherwise it is 19 minus S. Dates must be valid, with years from 0001 to 9999 and leap years respected. The answer fits in a signed 64-bit integer.
How can I count all matching numbers without trying every replacement for X? For example, 3X1X1639XX5XX1X6X85 should give 526315, and 30121952121234567XX should give 10.
hazard.of.hats:
For a fixed nonzero K, both S = K and S = 19 - K are possible. K = 0 only corresponds to S = 0.