Created
June 16, 2013 01:01
-
-
Save nephilim/5790274 to your computer and use it in GitHub Desktop.
Project Euler 09: Special Pythagorean Triplet
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
package ysl.p09 | |
object Pythagorean extends App { | |
// presume a > b > c | |
var count = 0; | |
for { | |
i <- 3 to 500 | |
j <- 2 until i | |
k <- (i-j) to j | |
if (j + k) > i // in triangle, 'a < b + c' is a geometrical axiom. | |
// 이렇게 하면 최악의 조합인 1000^3에 비해 훨씬 적은 | |
// 10385375개의 기본 조합을 기반으로 계산 | |
if (i*i == j*j + k*k) | |
if (i + j + k == 1000) | |
} | |
{ | |
count += 1 | |
println("%d) %d, %d, %d".format(count,i,j,k)) | |
} | |
//println(count) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment