fork download
  1. class Scratch {
  2. public static void main(String[] args) {
  3. int[] multipliers = {4,3,6,7,8,9,2,3,7,2,3,6,5,4};
  4.  
  5. String input = "VG0999999099999901012023099999999V99100012999999".strip();
  6. if (args.length > 0) {
  7. input = args[0].strip();
  8. }
  9. System.out.println(input);
  10.  
  11. // Strip all non-digit characters and convert to numeric array
  12. int[] digits = input.substring(2)
  13. .replaceAll("[^0-9]", "")
  14. .chars()
  15. .map(operand -> operand - '0')
  16. .toArray();
  17.  
  18. int[] shiftedMultipliers = new int[multipliers.length];
  19. for (int i = 0; i < multipliers.length; i++) {
  20. shiftedMultipliers[i] = multipliers[(digits.length - 1 - i) % multipliers.length];
  21. }
  22.  
  23. int parityDigit = 0;
  24. for (int i = 0 ; i < digits.length; i++) {
  25. parityDigit -= digits[i] * shiftedMultipliers[i % shiftedMultipliers.length];
  26.  
  27. }
  28.  
  29. parityDigit = Math.floorMod(parityDigit, 10);
  30. System.out.println(input + parityDigit);
  31. }
  32. }
Success #stdin #stdout 0.12s 58108KB
stdin
VG 0999999 0999999 01012023 099999999V99 1 00 0 1 2999994
stdout
VG0999999099999901012023099999999V99100012999999
VG0999999099999901012023099999999V991000129999997