Skip to content

Instantly share code, notes, and snippets.

@MinCha
Created August 7, 2015 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MinCha/a827f3649abbc283b169 to your computer and use it in GitHub Desktop.
Save MinCha/a827f3649abbc283b169 to your computer and use it in GitHub Desktop.
package susu
import org.junit.Test
import org.scalatest.junit.JUnitSuite
import scala.annotation.tailrec
import scala.util.Random
class SusuPremium extends JUnitSuite {
@Test def elect() {
case class ScoreBoard(name: String, score: List[Int] = List.empty) {
def sum = score.sum
}
@tailrec
def cast(c: List[ScoreBoard], i: Int): List[ScoreBoard] = {
def random = new Random().nextInt(6) + 1
if (i == 0) c
else cast(c.map(e => ScoreBoard(e.name, e.score :+ random)), i - 1)
}
def printPretty(title: String, scores: List[ScoreBoard]) {
println("=== " + title + "===")
scores.sortWith(_.sum > _.sum).foreach { e =>
val score = e.score.toString().replaceAll("List", "")
println("%s -> %d%s".format(e.name, e.score.sum, score))
}
}
def wait = Thread.sleep(1000 * 60)
val candidates = List(
"ian",
"glen",
"alisha",
"peter",
"howard",
"yao",
"ramon",
"sirius",
"tra",
"aiden",
"perry",
"baron",
"loki",
"young",
"truman",
"tony",
"viole",
"syd",
"kay",
"dayle",
"jaden",
"vayne",
"jin",
"ez",
"dark",
"kaya",
"rocky",
"dwan",
"caesar",
"hwanam",
"trace",
"cloud",
"diane",
"다니엘",
"luke",
"루이",
"아서",
"oliver").map(ScoreBoard(_))
val first = cast(candidates, 10)
printPretty("1010", first)
wait
val second = cast(first, 1)
printPretty("Second", second)
wait
val third = cast(second, 1)
printPretty("Third", third)
wait
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment