Skip to content

Instantly share code, notes, and snippets.

@hwiorn
hwiorn / euler0011.scala
Created May 28, 2013 16:01
euler 11번 문제
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}),
@hwiorn
hwiorn / euler0009.scala
Last active December 17, 2015 19:39
euler 9번 문제
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))
@hwiorn
hwiorn / euler0010.scala
Last active December 17, 2015 14:39
euler 10번 문제
println((2L to 2000000L).filter(BigInt(_).isProbablePrime(1000)).sum)
@hwiorn
hwiorn / euler0008.scala
Last active December 17, 2015 14:39
euler 8번 문제
println((
"73167176531330624919225119674426574742355349194934" +
"96983520312774506326239578318016984801869478851843" +
"85861560789112949495459501737958331952853208805511" +
"12540698747158523863050715693290963295227443043557" +
"66896648950445244523161731856403098711121722383113" +
"62229893423380308135336276614282806444486645238749" +
"30358907296290491560440772390713810515859307960866" +
"70172427121883998797908792274921901699720888093776" +
"65727333001053367881220235421809751254540594752243" +
@hwiorn
hwiorn / euler0007.scala
Last active December 17, 2015 14:38
euler 7번 문제
println(Stream.from(2).filter{BigInt(_).isProbablePrime(8)}(10001-1))
@hwiorn
hwiorn / euler0006.scala
Last active December 17, 2015 08:48
euler 6번 문제
println((math.pow((1 to 100).sum, 2) - (1 to 100).map(x=>x*x).sum).toInt)
@hwiorn
hwiorn / euler0005.scala
Last active December 17, 2015 08:48
euler 5번 문제
//소수(<20)의 최대 제곱수(<20)를 모두 곱셈
println((2 to 20).filter(BigInt(_).isProbablePrime(5)).
map(k => (1 to 4).map(math.pow(k, _)).
filter(_ <= 20).max).product.toInt)
@hwiorn
hwiorn / euler0004.scala
Last active December 17, 2015 00:10
euler 4번 문제
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)
@hwiorn
hwiorn / euler0003.scala
Last active December 17, 2015 00:10
euler 3번 문제
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))
@hwiorn
hwiorn / euler0002.scala
Last active December 16, 2015 11:29
euler 2번 문제
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))