Algori...MXX_002(3pm)
β¨ 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 π©βπ³
- 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 π«Ά)
- The sum of those products is computed. Just multiply, then add, bestie. Math ate π
- 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$numberconsists 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$numberis computed and concatenated to the end of$number. Returns the complete number with check digit, or''if$numberdoes not consist solely of digits and spaces. πbasenumber($number)β Returns the basenumber of$numberif$numberhas a valid check digit. Return''otherwise.checkdigit($number)β Returns the checkdigit of$numberif$numberhas 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
perlπͺCheckDigitswww.pruefziffernberechnung.dewww.cas.orghttp://www.cas.org/expertise/cascontent/registry/checkdig.html
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
- ubuntu noble: libalgorithm-checkdigits-perl 1.3.6-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libalgorithm-checkdigits-perl 1.3.6-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libalgorithm-checkdigits-perl 1.3.6-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms