Skip to content

Instantly share code, notes, and snippets.

@bigwheel
Created October 18, 2012 02:45
Show Gist options
  • Save bigwheel/3909586 to your computer and use it in GitHub Desktop.
Save bigwheel/3909586 to your computer and use it in GitHub Desktop.
ランダムに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