Created
December 27, 2014 10:59
-
-
Save marccarre/9690450322e6a75fd749 to your computer and use it in GitHub Desktop.
Scala - Winning combinations at the lottery
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
import scala.util.Random | |
def winningCombinationsFor(max: Int = 49, numDrawn: Int = 6, minNumToWin: Int = 3): Seq[Set[Int]] = { | |
val (draw, remainder) = Random.shuffle(1 to max).splitAt(numDrawn) | |
for { | |
numPickedFromDraw <- minNumToWin to numDrawn | |
subsetFromDraw <- draw.toSet.subsets(numPickedFromDraw) | |
subsetFromRemainder <- remainder.toSet.subsets(numDrawn - numPickedFromDraw) | |
} yield subsetFromDraw ++ subsetFromRemainder | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment