Skip to content

Instantly share code, notes, and snippets.

View elpa-obsolete.hs
#!/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 Apr 11, 2014
Factor cleave words in Haskell
View Cleave.hs
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)
View LookAndSay.exs
[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 Aug 29, 2015
Minimum sum of two numbers
View min_sum.factor
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
View column-name.factor
: >column-name ( n -- s ) "" [ over zero? ] [ [ 1 - 26 /mod 65 + ] dip swap prefix ] until nip ;
View treedepth.py
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
View SteppingStones.py
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))
View Simplification.py
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))
View output.txt
첫째날
10:00 소개
10:10 실습
10:30 휴식
0h 40m