Skip to content

Instantly share code, notes, and snippets.

View nephilim's full-sized avatar

Dongwook Lee nephilim

View GitHub Profile
@nephilim
nephilim / schonfinkelize-methods.js
Last active December 13, 2015 21:19
Created to demonstrate one of possible problems with a sample code in chapter four of the book Javascript Patterns. For more information, refer to an example on page 100 of the book
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",
# -*- coding=utf-8 -*-
__author__ = 'nephilim'
def curry(func, *args, **kwargs):
"""
객체 생성 후 다음과 같이 p의 메서드에 대해 커링을 시도
>>> p = Person()
>>> p.name
'lee'
@nephilim
nephilim / gist:5428120
Last active December 16, 2015 11:29
Project Euler 01: Multiples of 3 and 5
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)
}
@nephilim
nephilim / gist:5428154
Last active December 16, 2015 11:29
Project Euler 02: Even Fibonacci numbers
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)
}
@nephilim
nephilim / projecteuler05.scala
Last active December 17, 2015 11:59
Project Euler 05: Smallest Multiple
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)
}
@nephilim
nephilim / projecteuler09.scala
Created June 16, 2013 01:01
Project Euler 09: Special Pythagorean Triplet
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.
@nephilim
nephilim / projecteuler10.scala
Last active December 18, 2015 13:29
Project Euler 10: Summation of Primes
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: ...
}