Download the PHP package mistralys/subsetsum without Composer

On this page you can find all versions of the php package mistralys/subsetsum. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package subsetsum

Build Status

PHP SubsetSum implementation

Given a target number and a list of numbers, determines which number combinations equal the target number.

For example: With 25 as the target number, and 10, 5, 15 as the numbers list, this will determine that 25 = 10 + 15.

Requirements

Installation

Require the package via composer on the command line:

Or edit composer.json directly:

Usage

The create method is used to create a new instance, which can be used to retrieve matches, or to configure options:

Checking if there are any matches

Some methods like getShortestMatch() can return null, so it's best to check if there are matches beforehand.

Getting all matches

To retrieve all matching number combinations:

This will return an array like this:

NOTE: The numbers in each match result are always sorted in ascending order.

Getting the shortest match

The shortest match is the one that uses the least amount of number combinations.

In the example, this would return the following match array:

Getting the longest match

The longest match is the one that uses the highest amount of number combinations.

In the example, this would return the following match array:

Adjusting the amount of decimals & rounding

By default, the internal calculations will round the numbers to 2 decimals, using PHP's default "round up half" rounding. This can be easily adjusted to your needs:

The full list of possible modes can be found here:

http://www.php.net/manual/en/math.constants.php

Working with integers

Working in integer mode simply means using a precision of 0.

NOTE: The match arrays will contain integers, but which are still typed as floats. You will have to cast them to int as needed.

Performance

A word of caution: calculating subset sums has an exponential complexity the higher the amount of numbers to search through. You can easily bring your server to your knees with larger sets, so I would recommend setting some limits on the amount of numbers in your application.

Credits

The initial mechanism was inspired by this answer on StackOverflow:

http://stackoverflow.com/questions/4632322/finding-all-possible-combinations-of-numbers-to-reach-a-given-sum/#answer-43351998

There is also another interesting package that goes further than this:

https://github.com/pipan/subsetsum-php


All versions of subsetsum with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
ext-bcmath Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mistralys/subsetsum contains the following files

Loading the files please wait ....