class Scratch {
public static void main
(String[] args
) { int[] multipliers = {4,3,6,7,8,9,2,3,7,2,3,6,5,4};
String input
= "VG0999999099999901012023099999999V99100012999999".
strip(); if (args.length > 0) {
input = args[0].strip();
}
// Strip all non-digit characters and convert to numeric array
int[] digits = input.substring(2)
.replaceAll("[^0-9]", "")
.chars()
.map(operand -> operand - '0')
.toArray();
int[] shiftedMultipliers = new int[multipliers.length];
for (int i = 0; i < multipliers.length; i++) {
shiftedMultipliers[i] = multipliers[(digits.length - 1 - i) % multipliers.length];
}
int parityDigit = 0;
for (int i = 0 ; i < digits.length; i++) {
parityDigit -= digits[i] * shiftedMultipliers[i % shiftedMultipliers.length];
}
parityDigit
= Math.
floorMod(parityDigit,
10); System.
out.
println(input
+ parityDigit
); }
}
Y2xhc3MgU2NyYXRjaCB7CiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgaW50W10gbXVsdGlwbGllcnMgPSB7NCwzLDYsNyw4LDksMiwzLDcsMiwzLDYsNSw0fTsKCiAgICAgICAgU3RyaW5nIGlucHV0ID0gIlZHMDk5OTk5OTA5OTk5OTkwMTAxMjAyMzA5OTk5OTk5OVY5OTEwMDAxMjk5OTk5OSIuc3RyaXAoKTsKCQlpZiAoYXJncy5sZW5ndGggPiAwKSB7CgkJCWlucHV0ID0gYXJnc1swXS5zdHJpcCgpOwoJCX0KICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oaW5wdXQpOwoKICAgICAgICAvLyBTdHJpcCBhbGwgbm9uLWRpZ2l0IGNoYXJhY3RlcnMgYW5kIGNvbnZlcnQgdG8gbnVtZXJpYyBhcnJheQogICAgICAgIGludFtdIGRpZ2l0cyA9IGlucHV0LnN1YnN0cmluZygyKQogICAgICAgICAgICAgICAgLnJlcGxhY2VBbGwoIlteMC05XSIsICIiKQogICAgICAgICAgICAgICAgLmNoYXJzKCkKICAgICAgICAgICAgICAgIC5tYXAob3BlcmFuZCAtPiB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