de.bezier.math.combinatorics
Class Permutation

java.lang.Object
  extended by de.bezier.math.combinatorics.CombinatoricsBase
      extended by de.bezier.math.combinatorics.Permutation

public class Permutation
extends CombinatoricsBase

Changes in the order

A permutation is a change in the order of a given set of elements. An anagram or a deck of cards being shuffled are examples.

Given the elements [a,b,c] a permutation would produce:
[a,b,c], [a,c,b], [b,a,c], [b,c,a], [c,a,b], [c,b,a].

For 3 elements you will receive 3! (read "!" as factorial) results, that is 3*2*1 = 6

This code is based on: Michael Gillelands code, which he claims to be an implementation of
Kenneth H. Rosen, Discrete Mathematics and Its Applications, 2nd edition (NY: McGraw-Hill, 1991), pp. 282-284


Constructor Summary
Permutation(int elements)
           
 
Method Summary
 boolean hasMore()
          Are there more results available? Use in conditionals:
 int[] next()
          Return next result and update internal counter by one
 java.math.BigInteger position()
          Return copy of internal counter (number of results returned) as BigInteger
 int positionAsInt()
          Try to return internal counter (number of results returned) as int
 long positionAsLong()
          Try to return internal counter (number of results returned) as long
 float positionInPercent()
          How many percent of results returned so far?
 void rewind()
          As it says, rewinds the internal state to start over.
 
Methods inherited from class de.bezier.math.combinatorics.CombinatoricsBase
nextAndStep, numberOfElements, positionInPercent, total, totalAsInt, totalAsLong
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Permutation

public Permutation(int elements)
Parameters:
elements - Number of elements in the set to generate permutations for, should be larger than 0
Method Detail

rewind

public void rewind()
As it says, rewinds the internal state to start over.

Specified by:
rewind in class CombinatoricsBase

hasMore

public boolean hasMore()
Are there more results available? Use in conditionals:
if ( permuti.hasMore() ) { ... }

Specified by:
hasMore in class CombinatoricsBase
Returns:
true if there are more results available, false otherwise

next

public int[] next()
Return next result and update internal counter by one

Specified by:
next in class CombinatoricsBase
Returns:
Result as array of indices, see Combination intro for explaination

positionInPercent

public float positionInPercent()
How many percent of results returned so far?

Overrides:
positionInPercent in class CombinatoricsBase
Returns:
Number of returned results (internal state) in percent as float

positionAsInt

public int positionAsInt()
Try to return internal counter (number of results returned) as int

Overrides:
positionAsInt in class CombinatoricsBase
Returns:
Internal counter as int

positionAsLong

public long positionAsLong()
Try to return internal counter (number of results returned) as long

Overrides:
positionAsLong in class CombinatoricsBase
Returns:
Internal counter as long

position

public java.math.BigInteger position()
Return copy of internal counter (number of results returned) as BigInteger

Overrides:
position in class CombinatoricsBase
Returns:
Internal counter
See Also:
BigInteger


processing library Combinatorics by Florian Jenett. (c) 2010-2011