Algori...M11_013(3pm)
๐ NAME ๐
CheckDigits::M11_013 โ ok so bestie, this is the one that computes check digits for the VAT Registration Number (GR) โจ๐ฌ๐ท
๐ธ SYNOPSIS ๐ธ
use Algorithm::CheckDigits;
$ustid = CheckDigits('ustid_gr');
if ($ustid->is_valid('123456783')) {
# do something
}
$cn = $ustid->complete('12345678');
# $cn = '123456783'
$cd = $ustid->checkdigit('123456783');
# $cd = '3'
$bn = $ustid->basenumber('123456783');
# $bn = '12345678';
literally that's the whole vibe. build it, check it, split it back apart ๐ซถ
๐ฆ DESCRIPTION ๐ฆ
โจ ALGORITHM โจ
okay so here's the actual math, and ngl it's cute:
- Starting from the right, with the digit right before the checkdigit โ every digit gets weighted with
2 ** position. So the last digit times2, the next one times4, then8, and so on forever ๐ - Add all those weighted digits together, bestie. Just sum 'em. ๐งฎ
- Take that sum from step 2 and mod it by
11โmodulo 11icon behaviour. - If the number you got in step 3 is greater than
9, then the check sum is0โ otherwise it's just that sum itself. periodt. โจ
๐ METHODS ๐
is_valid($number)โ gives you back true only if$numberis made up of nothing but numbers, and the rightmost digit is a valid check digit per the algorithm above ๐. Anything else? false, sorry babe, returns false otherwise ๐complete($number)โ it computes the check digit for$numberand appends it right onto the end ๐. You get back the complete number with the check digit โ or''if$numberisn't solely digits ๐basenumber($number)โ hands you the basenumber of$number, but only if$numberhas a valid check digit โ . Otherwise it returns''.checkdigit($number)โ gives you the check digits of$number, again only if it has valid check digits. Otherwise it returns''๐ญ
๐ EXPORT ๐
None by default. like, zero. nothing. she stays private ๐
โญ AUTHOR โญ
Mathias Weidner, "<mamawe@cpan.org>" ๐ absolute legend, credit where credit is due fr fr.
๐ SEE ALSO ๐
perlCheckDigitswww.pruefziffernberechnung.de,- (and honestly, go read those, they ate) โจ
k bye bestie, go validate those numbers ๐
this was perl v5.36.0, dated 2022-10-13, and it's the Algori...M11_013(3pm) page โ mwah, slay, drink water ๐
๐ธ
๐ฆ 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