Created
June 2, 2014 15:02
-
-
Save takashima0411/6e2d16348bf9b5b34d6e to your computer and use it in GitHub Desktop.
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 Main { | |
def main(args:Array[String]) = { | |
findSTAP() | |
} | |
def findSTAP():Unit = | |
randomString(4) match { | |
case "STAP" => | |
println("STAP細胞") | |
println("見つかったよ!") | |
case other => | |
print(other + "細胞") | |
findSTAP() | |
} | |
def randomString(letterLength:Int):String = { | |
val r = new Random() | |
letterLength match { | |
case 0 => "" | |
case 1 => int2String(r.nextInt(25)) | |
case n => int2String(r.nextInt(25)) + randomSTAP( n - 1) | |
} | |
} | |
val int2String:PartialFunction[Int,String] = { | |
case 0 => "A" | |
case 1 => "B" | |
case 2 => "C" | |
case 3 => "D" | |
case 4 => "E" | |
case 5 => "F" | |
case 6 => "G" | |
case 7 => "H" | |
case 8 => "I" | |
case 9 => "J" | |
case 10 => "K" | |
case 11 => "L" | |
case 12 => "M" | |
case 13 => "N" | |
case 14 => "O" | |
case 15 => "P" | |
case 16 => "Q" | |
case 17 => "R" | |
case 18 => "S" | |
case 19 => "T" | |
case 20 => "U" | |
case 21 => "V" | |
case 22 => "W" | |
case 23 => "X" | |
case 24 => "Y" | |
case 25 => "Z" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment