This file contains hidden or 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
def gmax(s: String) = { | |
def r1(cond: Boolean, k: Array[List[Int]], x: Int, y: Int,xop: (Int)=>Int, yop: (Int)=>Int): Int = { | |
if(cond) k(y)(x) * k(yop(y))(xop(x)) * k(yop(yop(y)))(xop(xop(x))) * k(yop(yop(yop(y))))(xop(xop(xop(x)))) | |
else 1 | |
} | |
val k = s.split('\n').map{_.split(' ').map {_.toInt}.toList} | |
val w = k(1).length | |
List(for(y <- 0 to w-1; x <- 0 to w-1) | |
yield(List( | |
r1(x <= w-4, k, x, y, {_+1}, {n=>n}), |
This file contains hidden or 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
for(b<-(2 to 999); a<-(b to 999); if(a + b < 1000 && | |
math.pow(a, 2) + math.pow(b, 2) == math.pow(1000-a-b, 2))) | |
println(a * b * (1000-a-b)) |
This file contains hidden or 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
println((2L to 2000000L).filter(BigInt(_).isProbablePrime(1000)).sum) |
This file contains hidden or 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
println(( | |
"73167176531330624919225119674426574742355349194934" + | |
"96983520312774506326239578318016984801869478851843" + | |
"85861560789112949495459501737958331952853208805511" + | |
"12540698747158523863050715693290963295227443043557" + | |
"66896648950445244523161731856403098711121722383113" + | |
"62229893423380308135336276614282806444486645238749" + | |
"30358907296290491560440772390713810515859307960866" + | |
"70172427121883998797908792274921901699720888093776" + | |
"65727333001053367881220235421809751254540594752243" + |
This file contains hidden or 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
println(Stream.from(2).filter{BigInt(_).isProbablePrime(8)}(10001-1)) |
This file contains hidden or 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
println((math.pow((1 to 100).sum, 2) - (1 to 100).map(x=>x*x).sum).toInt) |
This file contains hidden or 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
//소수(<20)의 최대 제곱수(<20)를 모두 곱셈 | |
println((2 to 20).filter(BigInt(_).isProbablePrime(5)). | |
map(k => (1 to 4).map(math.pow(k, _)). | |
filter(_ <= 20).max).product.toInt) |
This file contains hidden or 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
println ((for(a <- (999 to 100 by -1); b <- (999 to 100 by -1); if((a * b).toString.reverse == (a * b).toString)) yield (a*b)).sorted.last) |
This file contains hidden or 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
def k(a: Long, s: Long = 2): Long = { | |
if(a < 2) s | |
else if(a % s == 0) k(a / s, s) | |
else k(a, s+1) | |
} | |
println(k(600851475143L)) |
This file contains hidden or 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
def fib(a: Int, b: Int, sum: Int, _until: Int): Int = { | |
return if(a < _until) fib(b, a+b, If(a%2==0) sum+a else sum, _until) else sum | |
} | |
println(fib(1, 1, 0, 4000000)) |
NewerOlder