Algori...MXX_002(3pm)

πŸ“¦
version 1.3.6 Β· 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

✨ Algori...MXX_002(3pm) ✨

okay so bestie, you found the Algori...MXX_002(3pm) page β€” it lives in the User Contributed Perl Documentation and it's tiny, it's focused, it's giving "one job, done flawlessly" πŸ’…. Underneath that abbreviated title is CheckDigits::MXX_002, and no cap, she only does one thing, but she EATS at it πŸ‘‘


🌸 NAME

CheckDigits::MXX_002 β€” compute check digits for CAS πŸ§ͺ


πŸŽ€ SYNOPSIS

use Algorithm::CheckDigits;

$cas = CheckDigits('cas');

if ($cas->is_valid('1333-74-0')) {
      # do something
}

$cn = $cas->complete('1333-74-');
# $cn = '1333-74-0'

$cd = $cas->checkdigit('1333-74-0');
# $cd = '0'

$bn = $cas->basenumber('1333-74-0');
# $bn = '1333-74-'

πŸ’– DESCRIPTION

🧚 ALGORITHM

lowkey the whole thing is three steps, like a little recipe πŸ‘©β€πŸ³

  1. Beginning right with the second digit all digits are weighted ascending starting with 1. (yes, second digit, from the right β€” read it again, it's not the first one, iykyk 🫢)
  2. The sum of those products is computed. Just multiply, then add, bestie. Math ate πŸ’…
  3. The checksum is the last digit of the sum from step 2 (modulo 10). So like, sum % 10, periodt.

πŸ’… METHODS

  • is_valid($number) β€” Returns true only if $number consists solely of numbers and the last digit is a valid check digit according to the algorithm given above. Returns false otherwise.
  • complete($number) β€” The check digit for $number is computed and concatenated to the end of $number. Returns the complete number with check digit, or '' if $number does not consist solely of digits and spaces. πŸ™ˆ
  • basenumber($number) β€” Returns the basenumber of $number if $number has a valid check digit. Return '' otherwise.
  • checkdigit($number) β€” Returns the checkdigit of $number if $number has a valid check digit. Return '' otherwise.
not me noticing the first one says "numbers" while the second one says "digits and spaces" πŸ‘€ that's just how the page tells it, so that's how I'm telling it. Keep your inputs clean either way πŸ’–

🌈 EXPORT

None by default. Like, nothing gets exported, zero, zilch, not even one function sneaking out the door. You call it through CheckDigits, that's the whole vibe.


πŸ‘‘ AUTHOR

Mathias Weidner, <mamawe@cpan.org> β€” legend behavior, honestly 🫢


πŸ¦‹ THANKS

Aaron W. West pointed me to a fault in the computing of the check digit. (a real one, bestie β€” public credit, we love to see it πŸ’€βœ¨)

HERMIER Christophe made me aware that CAS is now assigning 10-digit CAS Registry Numbers (http://www.cas.org/newsevents/10digitrn.html) β€” glow up for CAS, and a heads up for anyone coding against the old length, fr fr.


⭐ SEE ALSO


and that's the page πŸŽ€ it's perl v5.36.0, stamped 2022-10-13, and the whole thing is filed under the title Algori...MXX_002(3pm). stay checksummed, bestie, byeee πŸ«ΆπŸ’œ

πŸ“¦ where this page comes from