Algori...M10_011(3pm)
β¨ NAME β¨
CheckDigits::M10_011 β bestie, this one computes the check digits for UPS (US) π
π SYNOPSIS π
use Algorithm::CheckDigits;
$ups = CheckDigits('ups');
if ($ups->is_valid('1Z 591580 68 55587736')) {
# do something
}
$cn = $ups->complete('1Z 591580 68 5558773');
# $cn = '1Z 591580 68 55587736'
$cd = $ups->checkdigit('1Z 591580 68 55587736');
# $cd = '6'
$bn = $ups->basenumber('1Z 591580 68 55587736');
# $bn = '1Z 591580 68 5558773'
π DESCRIPTION π
πΈ ALGORITHM πΈ
okay so here's the whole vibe, step by step, no skips:
- Starting from the left, every number gets weighted alternately with
1and2β like a lil rhythm game β¨ - The sum of all those products is computed. Math is mathing. π₯
- The sum from step 3 is taken modulo
10. (yes bestie, the original really says "step 3" right there β we simply do not ask questions, we compute π) - The check digit is the difference between
10and the number from step 3. And that's the tea. π
π¦ METHODS π¦
is_valid($number)β returns true only if$numberconsists solely of numbers and its last digit is a valid check digit per the algorithm above. Anything else? Returns false. Periodt. πcomplete($number)β the check digit for$numbergets computed and glued onto the end of$number. Returns the complete number with its check digit β or''if$numberdoesn't consist solely of digits and spaces. Not a single extra character, she's picky like that. πbasenumber($number)β returns the basenumber of$numberif$numberhas a valid check digit. Otherwise it returns''. that's it, that's the whole function. π«Άcheckdigit($number)β returns the checkdigit of$numberif$numberhas a valid check digit. Otherwise? Say it with me: it returns''. β¨
π EXPORT π
None by default. Not one single thing, ngl. It's giving minimalist. π
π AUTHOR π
Mathias Weidner, "<mamawe@cpan.org>" β icon, legend, wrote the whole thing, we stan. π
π SEE ALSO π
perl, CheckDigits, www.pruefziffernberechnung.de. go read those too bestie, they're part of the lore π
that's the whole page!! this was perl v5.36.0, dated 2022-10-13, user contributed Perl documentation, and the page itself is Algori...M10_011(3pm) β slay, mwah, bye π§βπΈ
π¦ 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