in reply to Summing the odd/even digits of a larger number (for upc check digits)...a better way?

how about a tr/// based solution:
local $_ = $code; $check = tr/1/1/ + 6*tr/2/2/ + tr/3/3/ + 12*tr/4/4/ + tr/5/5/ + 18*tr/6/6/ + tr/7/7/ + 24*tr/8/8/ + tr/9/9/;
  • Comment on Re: Summing the odd/even digits of a larger number (for upc check digits)...a better way?
  • Download Code

Replies are listed 'Best First'.
Re^2: Summing the odd/even digits of a larger number (for upc check digits)...a better way?
by sgifford (Prior) on Jun 23, 2006 at 15:38 UTC
    That doesn't give a correct answer for the test UPC at the link provided by the OP, 064200115896. My interpretation of the algorithm was that whether to multiply by 3 or not based on whether the digit's position is odd or even, not its value.