score:0

(for {
  p <- input
  i <- 1 to p._2
} yield (p._1, i)).toset.subsets.map(_.tolist).tolist
  .filter(l =>  l.map(_._1).toset.size == l.size)

where input is list(list('k', 2), list('r', 2))

score:4

i got the answer thank you @poindextrose for the hint it lead me to the right answer. this is my solution

  def combinations(occurrences: occurrences): list[occurrences] = occurrences match {
    case list() => list(nil)
    case (c, n) :: others =>
       val tails = combinations(others)
       tails ::: (for {
            j <- tails
            i <- 1 to n
          } yield (c, i) :: j)

Related Query