YAPC::EU 2018 Glasgow Update!
This commit is contained in:
parent
22f33d4004
commit
4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions
25
Task/Pythagorean-triples/Scala/pythagorean-triples.scala
Normal file
25
Task/Pythagorean-triples/Scala/pythagorean-triples.scala
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
object PythagoreanTriples extends App {
|
||||
|
||||
println(" Limit Primatives All")
|
||||
|
||||
for {e <- 2 to 7
|
||||
limit = math.pow(10, e).longValue()
|
||||
} {
|
||||
var primCount, tripCount = 0
|
||||
|
||||
def parChild(a: BigInt, b: BigInt, c: BigInt): Unit = {
|
||||
val perim = a + b + c
|
||||
val (a2, b2, c2, c3) = (2 * a, 2 * b, 2 * c, 3 * c)
|
||||
if (limit >= perim) {
|
||||
primCount += 1
|
||||
tripCount += (limit / perim).toInt
|
||||
parChild(a - b2 + c2, a2 - b + c2, a2 - b2 + c3)
|
||||
parChild(a + b2 + c2, a2 + b + c2, a2 + b2 + c3)
|
||||
parChild(-a + b2 + c2, -a2 + b + c2, -a2 + b2 + c3)
|
||||
}
|
||||
}
|
||||
|
||||
parChild(BigInt(3), BigInt(4), BigInt(5))
|
||||
println(f"a + b + c <= ${limit.toFloat}%3.1e $primCount%9d $tripCount%12d")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue