A237042 UPC check digit for n.
7, 4, 1, 8, 5, 2, 9, 6, 3, 9, 6, 3, 0, 7, 4, 1, 8, 5, 2, 8, 5, 2, 9, 6, 3, 0, 7, 4, 1, 7, 4, 1, 8, 5, 2, 9, 6, 3, 0, 6, 3, 0, 7, 4, 1, 8, 5, 2, 9, 5, 2, 9, 6, 3, 0, 7, 4, 1, 8, 4, 1, 8, 5, 2, 9, 6, 3, 0, 7, 3, 0, 7, 4, 1, 8, 5, 2, 9, 6, 2, 9, 6, 3, 0, 7, 4, 1, 8, 5, 1, 8, 5, 2, 9, 6, 3
Offset: 1
Examples
a(13) = 0 because 1 * 1 + 3 * 3 = 10, giving a check digit of 0. a(14) = 7 because 1 * 1 + 4 * 3 = 13, and -13 = 7 mod 10. a(15) = 4 because 1 * 1 + 5 * 3 = 16, and -16 = 4 mod 10.
References
- David Salomon, Coding for Data and Computer Communications. New York: Springer (2006): 41 - 42.
Links
- GS1, Check Digit Calculator.
- Eric Weisstein's World of Mathematics, UPC.
Programs
-
PARI
a(n) = vecsum(digits(n,100)*31\-10) % 10; \\ Kevin Ryde, Oct 03 2023
Formula
a(n) = -( (Sum_{i=1..floor(L/2)} d(2i-1)) + 3*(Sum_{j=0..floor(L/2)} d(2j)) ) mod 10, where L is how many digits n has, d(L - 1) is the most significant digit of n, ..., and d(0) is the ones place digit.
Comments