Skip to content

Instantly share code, notes, and snippets.

@orclev
orclev / trie.py
Created February 29, 2012 04:17
Copied from vivekn / autocomplete / trie.py
"""
A fast data structure for searching strings with autocomplete support.
Copied this from https://github.com/vivekn/autocomplete/blob/master/trie.py
so I could embed it as a gist
"""
class Trie(object):
def __init__(self, value=None):
self.children = {}
self.value = value
@orclev
orclev / 14.hs
Created February 16, 2012 02:27
Euler problem 14
import Data.List
collatz :: Int -> Int
collatz 1 = 0
collatz n
| odd n = force $ (collatz $! 3*n+1) + 1
| even n = force $ (collatz $! div n 2) + 1
force x = x `seq` x