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)
Source: stackoverflow.com
Related Query
- list of all combinations
- Make List whose sublists cover all combinations of two input Lists
- Calculate all combinations of list when order doesn't matter
- How do I list all files in a subdirectory in scala?
- How to list all cassandra tables
- How to create all possible combinations from the elements of a list?
- Can I get a compile-time list of all of the case objects which derive from a sealed parent in Scala?
- Spark: produce RDD[(X, X)] of all possible combinations from RDD[X]
- How to check if list contains all the same values?
- How to list all the mount points in Azure Databricks?
- How to return all positives and the first negative number in a list using functional programming?
- How I can list all sbt dependencies?
- Use Spark to list all files in a Hadoop HDFS directory?
- Composing a list of all pairs
- Where can I find list of all special traits in Scala?
- Spark list all cached RDD names and unpersist
- List All Files in a Folder Sitting in a Data Lake
- Generating all possible combinations from a List[List[Int]] in Scala
- Scala Reflection: How to list all variables in scope?
- How to get the list of all test?
- Scala partial sum with current and all past elements in the list
- How can one list all csv files in an HDFS location within the Spark Scala shell?
- How to list all fields with a custom annotation using Scala's reflection at runtime?
- How to get list of all Route URL strings in play framework?
- Generalize list combinations to N lists
- How can I list all useable implicit conversion?
- How to list out all the files in the public/images directory in a Play Framework 2 Scala application?
- List all classes in object using reflection
- Why doesn't the Scala REPL list all possibilities when using TAB-completion?
- How to permute all combinations involving both lists, with each element preserved at their respective indices?
More Query from same tag
- SQLite for Scala
- Group by then sum of multiple columns in Scala Spark
- Spark ml cosine similarity: how to get 1 to n similarity score
- Scala Option Impact
- Map of Blobs in Cassandra table
- How to remove element in an array by index in a Dataframe in Spark
- Is there some reason to avoid return statements
- Spark Incorrectly Reading CSV
- What function is applied when a List is printed?
- How to parse JsArary in scala?
- Resolving implicit parameter at runtime
- Unit Test controllers in Play 2 framework with Scala
- Terminal animation - is clearing screen right approach?
- What is an Event Tag in lagom framework?
- Join two dataframes, sum up the values and get the maximum
- Scala: Implicit parameters should "without a prefix"?
- HList(DValue[A], DValue[B]) to HList(A, B) at library level?
- Is this build.sbt ok for packaging?
- Why test method fails?
- how to integrate Typesafe Console with an existing Maven Akka application?
- IntelliJ IDEA / Scala - cannot read resources
- akka actor testing using play
- Debugging errors in consuming asynchronous events in apache camel
- Why does this code not terminate
- Why does spray-json apply this hierarchy way in RootJsonFormat?
- How do I count all of the co-occurring elements in a document line using Spark?
- JSON support for companion object
- Spark explode nested JSON with Array in Scala
- Assigning each value as next item in Array in Scala
- Clustering data with categorical and numeric features in Apache Spark