PHP Classes

Lexographical PHP Permutations Generator: Generate permutations of characters of a string

Recommend this page to a friend!
  Info   View files Documentation   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 94 All time: 9,863 This week: 455Up
Version License PHP version Categories
permutations 1.0GNU General Publi...5Algorithms, PHP 5, Text processing
Description 

Author

This class can generate permutations of characters of a string.

It takes a given string and returns a new string with the same characters in a exchanged order.

The class can return all the permutation of a text string and iterate to next, previous, first and last permutations in the whole permutations sequence.

Picture of Jelle Sebreghts
  Performance   Level  
Name: Jelle Sebreghts <contact>
Classes: 7 packages by
Country: United States United States
Age: 34
All time rank: 1485222 in United States United States
Week rank: 321 Up31 in United States United States Up
Innovation award
Innovation award
Nominee: 4x

Documentation

Generates (lexographical) permutations.

Build Status Code Climate Test Coverage Issue Count

use Jelle_S\Util\Permutation\LexographicalPermutation;
$number = 12345;
$next = LexographicalPermutation::getNextPermutation($number);
print "The next lexographical permutation of {$number} is {$next}.\n";

$number = 32154;
$previous = LexographicalPermutation::getPreviousPermutation($number);
print "The previous lexographical permutation of {$number} is {$previous}.\n";

$first = LexographicalPermutation::getFirstPermutation($number);
print "The first lexographical permutation of {$number} is {$first}.\n";

$last = LexographicalPermutation::getLastPermutation($number);
print "The last lexographical permutation of {$number} is {$last}.\n";

$number = 3124;
$all = print_r(LexographicalPermutation::getAllPermutations($number), TRUE);
print "All lexographical permutations of {$number} are \n{$all}\n";

Output:

The next lexographical permutation of 12345 is 12354.
The previous lexographical permutation of 32154 is 32145.
The first lexographical permutation of 32154 is 12345.
The last lexographical permutation of 32154 is 54321.
All lexographical permutations of 3124 are
Array
(
    [0] => 1234
    [1] => 1243
    [2] => 1324
    [3] => 1342
    [4] => 1423
    [5] => 1432
    [6] => 2134
    [7] => 2143
    [8] => 2314
    [9] => 2341
    [10] => 2413
    [11] => 2431
    [12] => 3124
    [13] => 3142
    [14] => 3214
    [15] => 3241
    [16] => 3412
    [17] => 3421
    [18] => 4123
    [19] => 4132
    [20] => 4213
    [21] => 4231
    [22] => 4312
    [23] => 4321
)

  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Files folder imagetests (1 file)
Accessible without login Plain text file .codeclimate.yml Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file LexographicalPermutation.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Plain text file LexographicalPermutationTest.php Class Class source

 Version Control Reuses Unique User Downloads Download Rankings  
 100%1
Total:94
This week:0
All time:9,863
This week:455Up