Created
September 22, 2017 03:33
-
-
Save tjdett/3de0dd34e34e713d5bc04eb606c58623 to your computer and use it in GitHub Desktop.
Random team pick
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 | |
import scala.util.Try | |
import scala.collection.immutable.Stream | |
object PickRandom extends App { | |
def picksValid(picksStr: String) = | |
Try(picksStr.toInt).filter(_ > 0).isSuccess | |
override def main(args: Array[String]) { | |
val picksRequired = args.toList match { | |
case picksStr :: _ if picksValid(picksStr) => picksStr.toInt | |
case _ => 1 | |
} | |
val winOptions = Set("Home", "Away") | |
val winBy = Random.nextInt(30) | |
val picks = Stream.continually(Random.shuffle(winOptions).head) | |
.take(picksRequired) | |
// e.g. | |
// scala pick_random.scala 3 | |
// 3 Away Away Home | |
println(s"${winBy} "+picks.mkString(" ")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment