Skip to content

Instantly share code, notes, and snippets.

@marccarre
Created December 27, 2014 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marccarre/9690450322e6a75fd749 to your computer and use it in GitHub Desktop.
Save marccarre/9690450322e6a75fd749 to your computer and use it in GitHub Desktop.
Scala - Winning combinations at the lottery
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