Last active
January 30, 2016 13:53
-
-
Save toeic990/b5251e4baac03716aa0a to your computer and use it in GitHub Desktop.
pi で pi を求める (http://ch.nicovideo.jp/toeic990/blomaga/ar935178)
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
libraryDependencies += "org.skinny-framework" %% "skinny-http-client" % "2.0.2" | |
libraryDependencies += "org.slf4j" % "slf4j-simple" % "1.6.4" | |
mainClass := Some("Main") | |
scalaVersion := "2.11.7" |
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 skinny.http._ | |
object Main extends App { | |
val response: Response = HTTP.get("http://www.geocities.jp/f9305710/PAI1000000.html") | |
//val response: Response = HTTP.get("http://www.example.com") | |
var r = response.textBody | |
r = r.substring(r.indexOfSlice("141592"), r.lastIndexOfSlice("</FONT>")).withFilter(_.isDigit).map(c => c) | |
var incount = 0; | |
var oncount = 0; | |
var outcount = 0 | |
(r grouped 32) foreach { s => | |
if (s.length == 32) { | |
print("0." + s.substring(0, 14) + "\t0." + s.substring(15, 29) + "\n") | |
var p: Double = Math.pow(("0." + s.substring(0, 15)).toDouble, 2) + Math.pow(("0." + s.substring(16, 31)).toDouble, 2) | |
//print(p) | |
p match { | |
case q if q < 1 => incount += 1 | |
case 1 => oncount += 1 | |
case q if q > 1 => outcount += 1 | |
} | |
//println(" " + incount + " " + oncount + " " + outcount + " " + (4.0 * incount / (incount + outcount))) | |
println(" "+ (4.0 * incount / (incount + outcount))) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment