Skip to content

Instantly share code, notes, and snippets.

@zidarsk8
Created May 13, 2013 12:09
Show Gist options
  • Select an option

  • Save zidarsk8/5567867 to your computer and use it in GitHub Desktop.

Select an option

Save zidarsk8/5567867 to your computer and use it in GitHub Desktop.
simple occurrence combo
def combinations(occurrences: Occurrences): List[Occurrences] = {
def combo(l: Occurrences): List[Occurrences] = {
l match {
case Nil => List()
case occurrence :: tail => {
val rest = combo(tail)
val occurrenceList = (1 to occurrence._2).map( num => List( (occurrence._1,num) )).toList
occurrenceList ::: occurrenceList.flatMap(x => rest.map(y => x ::: y).toList).toList ::: rest
}
}
}
List()::combo(occurrences)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment