Algori...M10_011(3pm)

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

✨ 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:

  1. Starting from the left, every number gets weighted alternately with 1 and 2 β€” like a lil rhythm game ✨
  2. The sum of all those products is computed. Math is mathing. πŸ”₯
  3. 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 πŸ™ˆ)
  4. The check digit is the difference between 10 and the number from step 3. And that's the tea. πŸ‘‘

πŸ¦‹ METHODS πŸ¦‹

  • is_valid($number) β€” returns true only if $number consists 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 $number gets computed and glued onto the end of $number. Returns the complete number with its check digit β€” or '' if $number doesn't consist solely of digits and spaces. Not a single extra character, she's picky like that. πŸ’…
  • basenumber($number) β€” returns the basenumber of $number if $number has a valid check digit. Otherwise it returns ''. that's it, that's the whole function. 🫢
  • checkdigit($number) β€” returns the checkdigit of $number if $number has 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