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
function curry(fn) { | |
var slice = Array.prototype.slice; | |
var args = slice.call(arguments); | |
// curry.call(obj)의 형태로 호출했을 경우 | |
var self = this; | |
if (typeof(args[0]) != "function") { | |
// 예외 처리 | |
throw { name: "ArgumentException", |
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
# -*- coding=utf-8 -*- | |
__author__ = 'nephilim' | |
def curry(func, *args, **kwargs): | |
""" | |
객체 생성 후 다음과 같이 p의 메서드에 대해 커링을 시도 | |
>>> p = Person() | |
>>> p.name | |
'lee' |
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
package ysl.p01 | |
object Multiples extends App{ | |
val naturalNumber: Stream[Int] = Stream.cons(1, naturalNumber.map(_ + 1)) | |
val filtered = naturalNumber.filter(x => (x % 3 == 0 || x % 5 == 0)) | |
println(filtered.takeWhile(_ < 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
object Fibonacci extends App { | |
val fibonacci: Stream[Int] = Stream.cons( | |
1, | |
Stream.cons(2, | |
fibonacci.zip(fibonacci.tail).map( | |
zipped => zipped._1 + zipped._2))) | |
println(fibonacci.takeWhile(_ < 4000000).filter(_ % 2 == 0).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
package ysl.p05 | |
object SmallestMultple { | |
def discompose(n:Int):List[Int] = n match { | |
case 1 => Nil | |
case _ => { | |
val process = List.range(2,n +1).dropWhile( n % _ != 0) | |
val dividen = process.head | |
dividen :: discompose(n / dividen) | |
} |
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
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. |
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
package ysl.p10 | |
object PrimeSum extends App { | |
def naturals(from: Int): Stream[Int] = | |
Stream.cons(from, naturals(from + 1)) | |
def sieve(s: Stream[Int]): Stream[Int] = | |
Stream.cons(s.head, sieve(s.tail filter { _ % s.head != 0 })) | |
def primes = sieve(naturals(2).takeWhile( _ < 2000000)) | |
// TODO: ... | |
} |
OlderNewer