Skip to main content
Tweeted twitter.com/StackCodeGolf/status/1581480110925836289
Became Hot Network Question
added 3 characters in body
Source Link
math scat
  • 9.5k
  • 1
  • 24
  • 88

Given a message, append checksum digits using prime numbers as weights.


A checksum digit is used as an error-detection method.
Take, for instance, the error-detection method of the EAN-13 code:
The checksum digit is generated by:

  • Multiplying each digit in the message alternating by 1 and 3 (the weights)
  • Summing it up
  • Calculating the difference between the nearest multiple of 10 (Maximum possible value) and the sum

E.g:

1214563 -> 1*1 + 2*3 + 1*1 + 4*3 + 5*1 + 6*3 + 3*1 = 46 50 - 46 = 4 

Although the EAN-13 code can detect transposition errors (i.e. when two adjacent bits are switched, the checksum will be different) it can't detect an error when two bits with the same weight are swapped.
E.g.: 163 -> checksum digit 8, 361 -> checkdum digit 8

Using a prime checksum, with the first weight being the first prime number, the second weight being the second prime number, etc., errors can be detected when any two bits are swapped. Because the primes act as weights, you have an extra factor, the length of the message l:

  1. Multiply each digit in the message by the nth prime (First digit times the first prime, second digit times the second prime, etc.)
  2. Sum it up
  3. Calculate the sum of each prime up to the lth prime multiplied by 9 plus 1 (Maximum possible value)
  4. Subtract the second sum by the first sum

E.g.:

1214563 -> 1*2 + 2*3 + 1*5 + 4*7 + 5*11 + 6*13 + 3*17 = 225 9*(2+3+5+7+11+13+17) + 1 -> 523 523 - 225 = 298 

Rules

  • Take a decimal string, leading zeros are allowedprohibited
  • Output the checksum digits
  • Standard Loopholes apply
  • This is , the shortest answer wins!

Examples

[In]: 213 [Out]: 69 [In]: 89561 [Out]: 132 [In]: 999999 [Out]: 1 [In]: 532608352 [Out]: 534 

Given a message, append checksum digits using prime numbers as weights.


A checksum digit is used as an error-detection method.
Take, for instance, the error-detection method of the EAN-13 code:
The checksum digit is generated by:

  • Multiplying each digit in the message alternating by 1 and 3 (the weights)
  • Summing it up
  • Calculating the difference between the nearest multiple of 10 (Maximum possible value) and the sum

E.g:

1214563 -> 1*1 + 2*3 + 1*1 + 4*3 + 5*1 + 6*3 + 3*1 = 46 50 - 46 = 4 

Although the EAN-13 code can detect transposition errors (i.e. when two adjacent bits are switched, the checksum will be different) it can't detect an error when two bits with the same weight are swapped.
E.g.: 163 -> checksum digit 8, 361 -> checkdum digit 8

Using a prime checksum, with the first weight being the first prime number, the second weight being the second prime number, etc., errors can be detected when any two bits are swapped. Because the primes act as weights, you have an extra factor, the length of the message l:

  1. Multiply each digit in the message by the nth prime (First digit times the first prime, second digit times the second prime, etc.)
  2. Sum it up
  3. Calculate the sum of each prime up to the lth prime multiplied by 9 plus 1 (Maximum possible value)
  4. Subtract the second sum by the first sum

E.g.:

1214563 -> 1*2 + 2*3 + 1*5 + 4*7 + 5*11 + 6*13 + 3*17 = 225 9*(2+3+5+7+11+13+17) + 1 -> 523 523 - 225 = 298 

Rules

  • Take a decimal string, leading zeros are allowed
  • Output the checksum digits
  • Standard Loopholes apply
  • This is , the shortest answer wins!

Examples

[In]: 213 [Out]: 69 [In]: 89561 [Out]: 132 [In]: 999999 [Out]: 1 [In]: 532608352 [Out]: 534 

Given a message, append checksum digits using prime numbers as weights.


A checksum digit is used as an error-detection method.
Take, for instance, the error-detection method of the EAN-13 code:
The checksum digit is generated by:

  • Multiplying each digit in the message alternating by 1 and 3 (the weights)
  • Summing it up
  • Calculating the difference between the nearest multiple of 10 (Maximum possible value) and the sum

E.g:

1214563 -> 1*1 + 2*3 + 1*1 + 4*3 + 5*1 + 6*3 + 3*1 = 46 50 - 46 = 4 

Although the EAN-13 code can detect transposition errors (i.e. when two adjacent bits are switched, the checksum will be different) it can't detect an error when two bits with the same weight are swapped.
E.g.: 163 -> checksum digit 8, 361 -> checkdum digit 8

Using a prime checksum, with the first weight being the first prime number, the second weight being the second prime number, etc., errors can be detected when any two bits are swapped. Because the primes act as weights, you have an extra factor, the length of the message l:

  1. Multiply each digit in the message by the nth prime (First digit times the first prime, second digit times the second prime, etc.)
  2. Sum it up
  3. Calculate the sum of each prime up to the lth prime multiplied by 9 plus 1 (Maximum possible value)
  4. Subtract the second sum by the first sum

E.g.:

1214563 -> 1*2 + 2*3 + 1*5 + 4*7 + 5*11 + 6*13 + 3*17 = 225 9*(2+3+5+7+11+13+17) + 1 -> 523 523 - 225 = 298 

Rules

  • Take a decimal string, leading zeros are prohibited
  • Output the checksum digits
  • Standard Loopholes apply
  • This is , the shortest answer wins!

Examples

[In]: 213 [Out]: 69 [In]: 89561 [Out]: 132 [In]: 999999 [Out]: 1 [In]: 532608352 [Out]: 534 
fixed the worked example
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

Given a message, append checksum digits using prime numbers as weights.


A checksum digit is used as an error-detection method.
Take, for instance, the error-detection method of the EAN-13 code:
The checksum digit is generated by:

  • Multiplying each digit in the message alternating by 1 and 3 (the weights)
  • Summing it up
  • Calculating the difference between the nearest multiple of 10 (Maximum possible value) and the sum

E.g:

1214563 -> 1*1 + 2*3 + 1*1 + 4*3 + 5*1 + 6*3 + 3*1 = 46 50 - 46 = 4 

Although the EAN-13 code can detect transposition errors (i.e. when two adjacent bits are switched, the checksum will be different) it can't detect an error when two bits with the same weight are swapped.
E.g.: 163 -> checksum digit 8, 361 -> checkdum digit 8

Using a prime checksum, with the first weight being the first prime number, the second weight being the second prime number, etc., errors can be detected when any two bits are swapped. Because the primes act as weights, you have an extra factor, the length of the message l:

  1. Multiply each digit in the message by the nth prime (First digit times the first prime, second digit times the second prime, etc.)
  2. Sum it up
  3. Calculate the sum of each prime up to the lth prime multiplied by 9 plus 1 (Maximum possible value)
  4. Subtract the second sum by the first sum

E.g.:

1214563 -> 1*2 + 2*3 + 1*5 + 4*7 + 5*11 + 6*13 + 3*17 = 225 9*(2+3+5+7+11+13+152+3+5+7+11+13+17) + 1 -> 523 523 - 225 = 298 

Rules

  • Take a decimal string, leading zeros are allowed
  • Output the checksum digits
  • Standard Loopholes apply
  • This is , the shortest answer wins!

Examples

[In]: 213 [Out]: 69 [In]: 89561 [Out]: 132 [In]: 999999 [Out]: 1 [In]: 532608352 [Out]: 534 

Given a message, append checksum digits using prime numbers as weights.


A checksum digit is used as an error-detection method.
Take, for instance, the error-detection method of the EAN-13 code:
The checksum digit is generated by:

  • Multiplying each digit in the message alternating by 1 and 3 (the weights)
  • Summing it up
  • Calculating the difference between the nearest multiple of 10 (Maximum possible value) and the sum

E.g:

1214563 -> 1*1 + 2*3 + 1*1 + 4*3 + 5*1 + 6*3 + 3*1 = 46 50 - 46 = 4 

Although the EAN-13 code can detect transposition errors (i.e. when two adjacent bits are switched, the checksum will be different) it can't detect an error when two bits with the same weight are swapped.
E.g.: 163 -> checksum digit 8, 361 -> checkdum digit 8

Using a prime checksum, with the first weight being the first prime number, the second weight being the second prime number, etc., errors can be detected when any two bits are swapped. Because the primes act as weights, you have an extra factor, the length of the message l:

  1. Multiply each digit in the message by the nth prime (First digit times the first prime, second digit times the second prime, etc.)
  2. Sum it up
  3. Calculate the sum of each prime up to the lth prime multiplied by 9 plus 1 (Maximum possible value)
  4. Subtract the second sum by the first sum

E.g.:

1214563 -> 1*2 + 2*3 + 1*5 + 4*7 + 5*11 + 6*13 + 3*17 = 225 9*(2+3+5+7+11+13+15) + 1 -> 523 523 - 225 = 298 

Rules

  • Take a decimal string, leading zeros are allowed
  • Output the checksum digits
  • Standard Loopholes apply
  • This is , the shortest answer wins!

Examples

[In]: 213 [Out]: 69 [In]: 89561 [Out]: 132 [In]: 999999 [Out]: 1 [In]: 532608352 [Out]: 534 

Given a message, append checksum digits using prime numbers as weights.


A checksum digit is used as an error-detection method.
Take, for instance, the error-detection method of the EAN-13 code:
The checksum digit is generated by:

  • Multiplying each digit in the message alternating by 1 and 3 (the weights)
  • Summing it up
  • Calculating the difference between the nearest multiple of 10 (Maximum possible value) and the sum

E.g:

1214563 -> 1*1 + 2*3 + 1*1 + 4*3 + 5*1 + 6*3 + 3*1 = 46 50 - 46 = 4 

Although the EAN-13 code can detect transposition errors (i.e. when two adjacent bits are switched, the checksum will be different) it can't detect an error when two bits with the same weight are swapped.
E.g.: 163 -> checksum digit 8, 361 -> checkdum digit 8

Using a prime checksum, with the first weight being the first prime number, the second weight being the second prime number, etc., errors can be detected when any two bits are swapped. Because the primes act as weights, you have an extra factor, the length of the message l:

  1. Multiply each digit in the message by the nth prime (First digit times the first prime, second digit times the second prime, etc.)
  2. Sum it up
  3. Calculate the sum of each prime up to the lth prime multiplied by 9 plus 1 (Maximum possible value)
  4. Subtract the second sum by the first sum

E.g.:

1214563 -> 1*2 + 2*3 + 1*5 + 4*7 + 5*11 + 6*13 + 3*17 = 225 9*(2+3+5+7+11+13+17) + 1 -> 523 523 - 225 = 298 

Rules

  • Take a decimal string, leading zeros are allowed
  • Output the checksum digits
  • Standard Loopholes apply
  • This is , the shortest answer wins!

Examples

[In]: 213 [Out]: 69 [In]: 89561 [Out]: 132 [In]: 999999 [Out]: 1 [In]: 532608352 [Out]: 534 
edited body
Source Link
math scat
  • 9.5k
  • 1
  • 24
  • 88

Given a message, append checksum digits using prime numbers as weights.


A checksum digit is used as an error-detection method.
Take, for instance, the error-detection method of the EAN-13 code:
The checksum digit is generated by:

  • Multiplying each digit in the message alternating by 1 and 3 (the weights)
  • Summing it up
  • Calculating the difference between the nearest multiple of 10 (Maximum possible value) and the sum

E.g:

1214563 -> 1*1 + 2*3 + 1*1 + 4*3 + 5*1 + 6*3 + 3*1 = 46 50 - 46 = 4 

Although the EAN-13 code can detect transposition errors (i.e. when two adjacent bits are switched, the checksum will be different) it can't detect an error when two bits with the same weight are swapped.
E.g.: 163 -> checksum digit 8, 361 -> checkdum digit 8

Using a prime checksum, with the first weight being the first prime number, the second weight being the second prime number, etc., errors can be detected when any two bits are swapped. Because the primes act as weights, you have an extra factor, the length of the message l:

  1. Multiply each digit in the message by the nth prime (First digit times the first prime, second digit times the second prime, etc.)
  2. Sum it up
  3. Calculate the sum of each prime up to the lth prime multiplied by 9 plus 1 (Maximum possible value)
  4. Subtract the second sum by the first sum

E.g.:

1214563 -> 1*2 + 2*3 + 1*5 + 4*7 + 5*11 + 6*13 + 3*17 = 225 9*(2+3+5+7+11+13+15) + 1 -> 505523 505523 - 225 = 280298 

Rules

  • Take a decimal string, leading zeros are allowed
  • Output the checksum digits
  • Standard Loopholes apply
  • This is , the shortest answer wins!

Examples

[In]: 213 [Out]: 6869 [In]: 89561 [Out]: 131132 [In]: 999999 [Out]: 01 [In]: 532608352 [Out]: 533534 

Given a message, append checksum digits using prime numbers as weights.


A checksum digit is used as an error-detection method.
Take, for instance, the error-detection method of the EAN-13 code:
The checksum digit is generated by:

  • Multiplying each digit in the message alternating by 1 and 3 (the weights)
  • Summing it up
  • Calculating the difference between the nearest multiple of 10 (Maximum possible value) and the sum

E.g:

1214563 -> 1*1 + 2*3 + 1*1 + 4*3 + 5*1 + 6*3 + 3*1 = 46 50 - 46 = 4 

Although the EAN-13 code can detect transposition errors (i.e. when two adjacent bits are switched, the checksum will be different) it can't detect an error when two bits with the same weight are swapped.
E.g.: 163 -> checksum digit 8, 361 -> checkdum digit 8

Using a prime checksum, with the first weight being the first prime number, the second weight being the second prime number, etc., errors can be detected when any two bits are swapped. Because the primes act as weights, you have an extra factor, the length of the message l:

  1. Multiply each digit in the message by the nth prime (First digit times the first prime, second digit times the second prime, etc.)
  2. Sum it up
  3. Calculate the sum of each prime up to the lth prime multiplied by 9 plus 1 (Maximum possible value)
  4. Subtract the second sum by the first sum

E.g.:

1214563 -> 1*2 + 2*3 + 1*5 + 4*7 + 5*11 + 6*13 + 3*17 = 225 9*(2+3+5+7+11+13+15) + 1 -> 505 505 - 225 = 280 

Rules

  • Take a decimal string, leading zeros are allowed
  • Output the checksum digits
  • Standard Loopholes apply
  • This is , the shortest answer wins!

Examples

[In]: 213 [Out]: 68 [In]: 89561 [Out]: 131 [In]: 999999 [Out]: 0 [In]: 532608352 [Out]: 533 

Given a message, append checksum digits using prime numbers as weights.


A checksum digit is used as an error-detection method.
Take, for instance, the error-detection method of the EAN-13 code:
The checksum digit is generated by:

  • Multiplying each digit in the message alternating by 1 and 3 (the weights)
  • Summing it up
  • Calculating the difference between the nearest multiple of 10 (Maximum possible value) and the sum

E.g:

1214563 -> 1*1 + 2*3 + 1*1 + 4*3 + 5*1 + 6*3 + 3*1 = 46 50 - 46 = 4 

Although the EAN-13 code can detect transposition errors (i.e. when two adjacent bits are switched, the checksum will be different) it can't detect an error when two bits with the same weight are swapped.
E.g.: 163 -> checksum digit 8, 361 -> checkdum digit 8

Using a prime checksum, with the first weight being the first prime number, the second weight being the second prime number, etc., errors can be detected when any two bits are swapped. Because the primes act as weights, you have an extra factor, the length of the message l:

  1. Multiply each digit in the message by the nth prime (First digit times the first prime, second digit times the second prime, etc.)
  2. Sum it up
  3. Calculate the sum of each prime up to the lth prime multiplied by 9 plus 1 (Maximum possible value)
  4. Subtract the second sum by the first sum

E.g.:

1214563 -> 1*2 + 2*3 + 1*5 + 4*7 + 5*11 + 6*13 + 3*17 = 225 9*(2+3+5+7+11+13+15) + 1 -> 523 523 - 225 = 298 

Rules

  • Take a decimal string, leading zeros are allowed
  • Output the checksum digits
  • Standard Loopholes apply
  • This is , the shortest answer wins!

Examples

[In]: 213 [Out]: 69 [In]: 89561 [Out]: 132 [In]: 999999 [Out]: 1 [In]: 532608352 [Out]: 534 
Source Link
math scat
  • 9.5k
  • 1
  • 24
  • 88
Loading