Created
August 27, 2014 02:28
-
-
Save bluebear94/4f50ca16a986b07f91cd to your computer and use it in GitHub Desktop.
Determines whether you're Steve or Alex.
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 java.util.UUID | |
import scala.io.Source | |
object SteveOrAlex { | |
def main(args: Array[String]) { | |
val name = args(0) | |
println(s"Stats for $name") | |
val theID = uuid(name) | |
println(s"UUID: $theID") | |
val hash = theID.hashCode | |
println(s"Hash: $hash") | |
println("You're a" + (if (hash % 2 == 0) " Steve" else "n Alex")) | |
} | |
def uuid(s: String): UUID = { | |
try { | |
UUID.fromString(s.replaceFirst("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5")) | |
} catch { | |
case _: Exception => { | |
val src = Source.fromURL("https://api.mojang.com/users/profiles/minecraft/" + s) | |
val lines = src.getLines | |
val firstLine = lines.next | |
println(s"firstLine = $firstLine") | |
uuid(firstLine.substring(7, 39)) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment