Last active
May 14, 2018 00:04
-
-
Save sanjivsahayamrea/2fb73c1a11cbdd407a2df88c402399b5 to your computer and use it in GitHub Desktop.
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 findWinner(candidates: Seq[String], rotations: Int): Option[String] = { | |
if (candidates.isEmpty || rotations <= 0) None | |
else { | |
val numCandidates = candidates.length | |
val randomIndexes = List.fill(rotations)(scala.util.Random.nextInt(numCandidates)) | |
val meanOp = randomIndexes.drop(rotations / 2).headOption | |
meanOp.map(candidates(_)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment