Encode::Positive::Pairs - encode pairs of positive integers as a single integer and vice versa
use Encode::Positive::Pairs; my ($i, $j) = Encode::Positive::Pairs::singleToPair(4); ok $i == 1 && $j == 1; ok 4 == Encode::Positive::Pairs::pairToSingle(1, 1);
Larger numbers are automatically supported via Math::BigInt:
my $n = '1'.('0'x121).'1'; my ($i, $j) = Encode::Positive::Pairs::singleToPair($n); ok $i == "1698366900312561357458283662619176178439283700581622961703001"; ok $j == "12443768723418389130558603579477804607257435053187857770063795"; ok $n == Encode::Positive::Pairs::pairToSingle($i, $j);
Encode pairs of positive integers as a single integer and vice-versa
Decode a single integer into a pair of integers
1 $N Number to decode
Return the single integer representing a pair of integers
1 $I First number of pair to encode 2 $J Second number of pair to encode
The sum of the numbers from 1 to a specified number
1 $t The number of leading integers to sum
Return the pair that encode to the number specified
1 $n Number to decode 2 $l Lower limit 3 $u Upper limit
equation
pairToSingle
search
singleToPair
This module is written in 100% Pure Perl and, thus, it is easy to read, use, modify and install.
Standard Module::Build process for building and installing modules:
perl Build.PL ./Build ./Build test ./Build install
philiprbrenan@gmail.com
http://www.appaapps.com
Copyright (c) 2016-2017 Philip R Brenan.
This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
To install Encode::Positive::Pairs, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Encode::Positive::Pairs
CPAN shell
perl -MCPAN -e shell install Encode::Positive::Pairs
For more information on module installation, please visit the detailed CPAN module installation guide.