Created
May 13, 2013 12:09
-
-
Save zidarsk8/5567867 to your computer and use it in GitHub Desktop.
simple occurrence combo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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