1.
Match rating: 74.04% · See similar code snippets
java logo
public int test(Permutation permutation) {
        for (int i = 0; i < size; i++) {
            int x = permutation.get(base.get(i));
            Permutation h = permutations[i][x];
            if (h == null) {
                return i;
            } else {
                permutation.setTo(h.invert().multiply(permutation));
            }
        }
        return size;
    }
2.
Match rating: 73.83% · See similar code snippets
java logo
public Permutation multiply(Permutation other) {
        Permutation newPermutation = new Permutation(values.length);
        for (int i = 0; i < values.length; i++) {
            newPermutation.values[i] = this.values[other.values[i]];
        }
        return newPermutation;
    }
3.
dwdyer/uncommons-maths · PermutationGenerator.java
Match rating: 73.6% · See similar code snippets
java logo
public List<T> nextPermutationAsList()
    {
        List<T> permutation = new ArrayList<T>(elements.length);
        return nextPermutationAsList(permutation);
    }
4.
biojava/biojava · RotationSolver.java
Match rating: 73.58% · See similar code snippets
java logo
private Rotation isValidPermutation(List<Integer> permutation) {
		if (permutation.size() == 0) {
			return null;
		}

		// cached value
		if (evaluatedPermutations.containsKey(permutation)) {
			return evaluatedPermutations.get(permutation);
		}

		// check if permutation is allowed
		if (! isAllowedPermutation(permutation)) {
			evaluatedPermutations.put(permutation, null);
			return null;
		}

		// check if superimposes
		Rotation rot = superimposePermutation(permutation);
		return rot;
	}
5.
Match rating: 73.28% · See similar code snippets
java logo
@Override
  public int[] next() {
    if (numLeft == 0) {
      throw new NoSuchElementException();
    }

    if (numLeft == total) {
      numLeft--;
      return ArrayUtils.copyOf(permutation, permutation.length);
    }

    // Find largest index j with a[j] < a[j+1]
    int j = permutation.length - 2;
    while (permutation[j] > permutation[j + 1]) {
      j--;
    }

    // Find index k such that a[k] is smallest integer
    // greater than a[j] to the right of a[j]
    int k = permutation.length - 1;
    while (permutation[j] > permutation[k]) {
      k--;
    }

    // Interchange a[j] and a[k]
    int temp = permutation[k];
    permutation[k] = permutation[j];
    permutation[j] = temp;

    // Put tail end of permutation after jth position in increasing order
    int r = permutation.length - 1;
    int s = j + 1;

    while (r > s) {
      temp = permutation[s];
      permutation[s] = permutation[r];
      permutation[r] = temp;
      r--;
      s++;
    }

    numLeft--;
    return ArrayUtils.copyOf(permutation, permutation.length);
  }
6.
biojava/biojava · PermutationGroup.java
Match rating: 73.16% · See similar code snippets
java logo
public static int getOrder(List<Integer> permutation) {
		List<Integer> copy = new ArrayList<Integer>(permutation);
		for (int i = 0, n = permutation.size(); i < n; i++) {
			copy = combine(copy, permutation);
			if (copy.equals(permutation)) {
				return i + 1;
			}
		}
		return 0;
	}
7.
biojava/biojava · PermutationGroup.java
Match rating: 72.65% · See similar code snippets
java logo
public static List<Integer> combine(List<Integer> permutation1, List<Integer> permutation2) {
		List<Integer> intermediate = new ArrayList<Integer>(permutation1.size());
		for (int i = 0, n = permutation1.size(); i < n; i++) {
			intermediate.add(permutation2.get(permutation1.get(i)));
		}
		return intermediate;
	}
8.
apache/groovy · fannkuch.java
Match rating: 72.27% · See similar code snippets
java logo
private static final void next_perm(final int[] permutation, int position)
    {
        int perm0 = permutation[0];

        for (int i = 0; i < position; ++i)
            permutation[i] = permutation[i + 1];
        permutation[position] = perm0;
    }
9.
Match rating: 72.04% · See similar code snippets
java logo
public List<Permutation> all() {
        final List<Permutation> permutations = new ArrayList<Permutation>();
        Backtracker counter = new Backtracker() {

            @Override
            public void applyTo(Permutation p) {
                permutations.add(p);
            }

            @Override
            public boolean isFinished() {
                return false;
            }
        };
        this.apply(counter);
        return permutations;
    }
10.
biojava/biojava · SystematicSolver.java
Match rating: 71.84% · See similar code snippets
java logo
private void solve() {
		initialize();
		int n = subunits.getSubunitCount();
		PermutationGenerator g = new PermutationGenerator(n);

		// loop over all permutations
		while (g.hasMore()) {
			int[] perm = g.getNext();
			List<Integer> permutation = new ArrayList<Integer>(perm.length);
			for (int j = 0; j < n; j++) {
				permutation.add(perm[j]);
			}

			if (! isValidPermutation(permutation)) {
				continue;
			}

			boolean newPermutation = evaluatePermutation(permutation);
			if (newPermutation) {
				completeRotationGroup();
			}

			if (rotations.getOrder() >= subunits.getSubunitCount()) {
				return;
			}
		}
	}