hxtree / sumfinder
This program allows for an integer array to be passed in and will then output all the pairs that add up to the sum.
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Type:project
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.17@dev
- phpunit/phpunit: ^8
This package is auto-updated.
Last update: 2024-10-26 12:31:39 UTC
README
SumFinder accepts an array of integers and finds which operands sum equals the desired value.
Usage
require __DIR__ . '/../vendor/autoload.php'; $sum_finder = new SumFinder(); $sum_finder->setSumValue(10); $sum_finder->setIntArray(1,1,2,4,4,5,5,5,6,7,9); /* * output all pairs (includes duplicates and the reversed order pairs) * [1,9], [1,9], [4,6], [4,6], [5,5], [5,5], [5,5], [5,5], [5,5], [5,5] */ echo $sum_finder->getAllPairs() . PHP_EOL; /* * output unique pairs only once (removes the duplicates but includes the reversed ordered pairs) * [1,9], [4,6], [5,5], [6,4], [9,1] */ echo $sum_finder->getUniquePairs() . PHP_EOL; /* * output the same combo pair only once (removes the reversed ordered pairs) * [1,9], [4,6], [5,5] */ echo $sum_finder->getComboPairs() . PHP_EOL;
Installation
Via Composer
SumFinder is available on Packagist.
Install with Composer:
composer require hxtree/sumfinder
Examples
Learn how SumFinder can be used through our Docs.