Created
October 18, 2012 02:45
-
-
Save bigwheel/3909586 to your computer and use it in GitHub Desktop.
ランダムに2チームへ分けるスクリプト scala編
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 | |
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