Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ランダムに2チームへ分けるスクリプト scala編
import scala.util.Random
object lunch_script {
def main(args: Array[String]) : Unit = {
val splitMember = shuffleAndSplit(args.toList, 20121018)
println(splitMember._1)
println(splitMember._2)
}
def shuffleAndSplit(member: List[String], date: Long) : (List[String], List[String]) = {
val random = new Random(date)
val shuffled = random.shuffle(member)
split(shuffled, true)
}
def split(member: List[String], nextTeamIsFirst: Boolean) : (List[String], List[String]) = {
member match {
case List() => (List.empty[String], List.empty[String])
case _ =>
val r = split(member.tail, !nextTeamIsFirst)
if (nextTeamIsFirst)
(member.head :: r._1, r._2)
else
(r._1, member.head :: r._2)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.