Skip to content

Instantly share code, notes, and snippets.

View nephilim's full-sized avatar

Dongwook Lee nephilim

View GitHub Profile
@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: ...
}
@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 / 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 / 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 / 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)
}
# -*- coding=utf-8 -*-
__author__ = 'nephilim'
def curry(func, *args, **kwargs):
"""
객체 생성 다음과 같이 p의 메서드에 대해 커링을 시도
>>> p = Person()
>>> p.name
'lee'
@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",
@nephilim
nephilim / memoization-with-anonymous-func.js
Last active December 13, 2015 18:09
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 92 of the book.
var func = function() {
if ( !func.cache ) {
console.log("cache initialized @" + new Date());
func.cache = "complex result";
}
return func.cache;
};
var func2 = func;
@nephilim
nephilim / scala-competition-spec.scala
Created May 13, 2012 05:29
ScalaTest Spec for 20120513 Lasdan Competition
package pis.chap22.multimap
import org.junit.runner.RunWith
import org.scalatest.Spec
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class LasMultiMapSpec extends Spec {
describe("정의한 LasDan MultiMap의 기본 동작을 확인한다") {
it ("기본 동작") {
@nephilim
nephilim / la-o-dan-s3-noti.markdown
Created July 9, 2011 07:00
라오단 3기 시작 공지

새로운 시즌의 스터디를 시작하며

첫 모임을 다음 주 토요일(7월 16일)에 할 예정입니다. 새로운 시작에 앞서 몇 가지 내용을 공유합니다.

2시즌

이전 시즌에 대한 내용을 요약하면 다음과 같습니다