I am looking for the scala way to give all permutations without repetitions. I know there are some postings on this site already but they seem to have a slightly different problem.
I am searching for all permutations with repetitions. For example:
combine(List('A','C','G'))
Should yield:
List(List('A'.'A','A'),List('A'.'A','C'),List('A'.'A','G'),List('A'.'C','A'),
List('A'.'C',''C), ... List('G'.'G','G')
I am sorry if my problem is already solved but I was not able to find it.
Thanks in advance.
EDIT:
My own approach (doesn't compile):
def combine(size: Int = sym.length) : List[List[T]] = {
size match {
case 0 => List()
case 1 => sym.toList.map(List(_))
case _ => for (el <- sym) yield el :: combine(size-1)
}
}
sym is an array member of a class which contains all the symbols to be combined.