Remove single-element permutations

This commit is contained in:
Gabriel Tofvesson 2019-11-06 06:22:10 +01:00
parent ade18b5ccf
commit 12572889a1

View File

@ -22,6 +22,7 @@ class Permutation {
*/ */
operator fun times(perm: Permutation) operator fun times(perm: Permutation)
= Permutation(this(*perm(*orderedElements)).zip(orderedElements) // Generate transpositions = Permutation(this(*perm(*orderedElements)).zip(orderedElements) // Generate transpositions
.filterNot{ it.first == it.second }
.foldRight(ArrayList<Pair<Char, Char>>()){ // Deduplicate transpositions .foldRight(ArrayList<Pair<Char, Char>>()){ // Deduplicate transpositions
insert, acc -> insert, acc ->
acc.firstOrNull { acc.firstOrNull {
@ -47,4 +48,4 @@ class Permutation {
return elements return elements
} }
} }