Philip R Brenan

Name

Encode::Positive::Pairs - encode pairs of positive integers as a single integer and vice versa

Synopsis

 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);

Description

Convert

Encode pairs of positive integers as a single integer and vice-versa

singleToPair($)

Decode a single integer into a pair of integers

  1  $N  Number to decode  

pairToSingle($$)

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  

Private Methods

equation($)

The sum of the numbers from 1 to a specified number

  1  $t  The number of leading integers to sum  

search($$$)

Return the pair that encode to the number specified

  1  $n  Number to decode  
  2  $l  Lower limit       
  3  $u  Upper limit       

Index

equation

pairToSingle

search

singleToPair

Installation

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

Author

philiprbrenan@gmail.com

http://www.appaapps.com

Copyright

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.