Skip to content

Instantly share code, notes, and snippets.

@eungju
eungju / elpa-obsolete.hs
Last active August 29, 2015 13:58
ELPA utility
#!/usr/bin/env runghc
import Control.Monad
import Data.Function
import Data.Functor
import Data.List
import System.Directory
import System.FilePath
data ELPA = ELPA FilePath
@eungju
eungju / Cleave.hs
Created April 11, 2014 11:32
Factor cleave words in Haskell
bi :: (a -> b) -> (a -> c) -> a -> (b, c)
bi f g (x) = (f x, g x)
bi2 :: (a -> b -> c) -> (a -> b -> d) -> (a, b) -> (c, d)
bi2 f g (x, y) = (f x y, g x y)
tri :: (a -> b) -> (a -> c) -> (a -> d) -> a -> (b, c, d)
tri f g h (x) = (f x, g x, h x)
tri2 :: (a -> b -> c) -> (a -> b -> d) -> (a -> b -> e) -> (a, b) -> (c, d, e)
@eungju
eungju / LookAndSay.exs
Created October 31, 2014 02:24
Look and Say
[1] |> Stream.iterate(fn(x) -> x |> Enum.chunk_by(&+/1) |> Enum.flat_map(fn([x|_]=c) -> [x, Enum.count(c)] end) end) |> Enum.take(10)
@eungju
eungju / min_sum.factor
Last active August 29, 2015 14:10
Minimum sum of two numbers
natural-sort [ zero? ] partition dup length 2 < [ 2drop -1 ] [ 2 cut swapd 3append zip-index [ second even? ] partition [ keys 0 [ swap 10 * + ] reduce ] bi@ + ] if
natural-sort [ zero? ] partition dup length 2 < [ 2drop -1 ] [ 2 cut surround zip-index [ second even? ] partition [ keys 0 [ swap 10 * + ] reduce ] bi@ + ] if
: >column-name ( n -- s ) "" [ over zero? ] [ [ 1 - 26 /mod 65 + ] dip swap prefix ] until nip ;
dup 1 tail zip [ [ second ] [ first ] bi - ] sort-with first
import unittest
def has_branches(tree):
return len(tree) >= 1
def depth(tree):
if has_branches(tree):
return 1 + max(map(depth, tree))
else:
return 1
import unittest
def has_branch(tree):
return False
class DepthTest(unittest.TestCase):
#I guess, testing existence of branches might be useful to calculate the depth of tree.
def test_has_branch(self):
tree = []
self.assertFalse(has_branch(tree))
import unittest
def depth(tree):
return 1
class DepthTest(unittest.TestCase):
#Simplest tree is a tree which has just one node with no branches. In that case, the depth is 1.
def test_no_children(self):
tree = []
self.assertEquals(1, depth(tree))
첫째날
10:00 소개
10:10 실습
10:30 휴식
0h 40m