Last active
August 29, 2015 14:27
-
-
Save sebnozzi/6a4b1717d4cd36b08a2c to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* @author Sebastian Nozzi | |
*/ | |
object RaffleApp extends App with HelperMethods { | |
lazy val numberCandidates: Set[Int] = { | |
val allNumbers = (1 to 17).toSet | |
val numbersThatWonSomething = Set[Int]() | |
allNumbers.diff(numbersThatWonSomething) | |
} | |
lazy val peopleCandidates: Set[String] = { | |
// Outcomment winners! | |
val peopleThatDidNotWinAnythingYet = | |
Seq( | |
"Person1", | |
"Person2", | |
"Person3", | |
//"Person4", // this guy already won something | |
"Person5") | |
assert(hasUniqueElements(peopleThatDidNotWinAnythingYet), "Should have unique names!") | |
peopleThatDidNotWinAnythingYet.toSet | |
} | |
val chosenOne = chooseOne(numberCandidates) | |
println(s"And the chosen one is... ${chosenOne}") | |
} | |
trait HelperMethods { | |
protected def hasUniqueElements[A](a: Seq[A]): Boolean = { | |
a.toSet.size == a.size | |
} | |
protected def chooseOne[A](candidates: Set[A]): A = { | |
Random.shuffle(candidates.toSeq).head | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment