Skip to content

Instantly share code, notes, and snippets.

View damzam's full-sized avatar

David Morton damzam

View GitHub Profile

Keybase proof

I hereby claim:

  • I am damzam on github.
  • I am dmorton (https://keybase.io/dmorton) on keybase.
  • I have a public key ASBL4_oC6IYBJBjG_3FhblZP1R0LDof0wjP6huHis6TnpQo

To claim this, I am signing this object:

@damzam
damzam / cheapest_path.py
Created June 14, 2015 05:21
Use dynamic programming to find the shortest path through nodes in a binary lattice structure
"""
Figure out the smallest sum for a binary lattice
of nodes where children are shared.
e.g.
1
/ \
4 5
/ \ / \
@damzam
damzam / superset.py
Created June 13, 2015 03:39
Create a superset efficiently in Python
#!/usr/bin/env python
"""
Create a superset from the integers provided
e.g. ./superset.py 1 2 3
[set([]), set([1]), set([2]), set([3]), set([1, 2]),
set([1, 3]), set([2, 3]), set([1, 2, 3])]
"""
import sys
@damzam
damzam / generate_siblings.py
Created June 12, 2015 23:16
Create sibling relationships within a Binary Tree in O(1) memory
#!/usr/bin/env python
"""
Find the right sibling in a Binary Tree that's not fully populated
e.g.
1
/ \
2 6
/ \ \
@damzam
damzam / lru_cache.py
Created June 12, 2015 16:28
Implement a simple LRUCache in Python
#!/usr/bin/env python
"""
Python's OrderedDict is an ideal data structure
to create an LRU cache
"""
from collections import OrderedDict
class LRUCache(object):
@damzam
damzam / encrypt_a_lowercase_string.py
Last active August 29, 2015 14:22
Encrypt a lowercase string into another lowercase string with no spaces
#!/usr/bin/env python
"""
encrypt and descript lowercase strings without using
but lowercase strings
"""
from string import lowercase
from random import choice
MAX_GARBAGE_LENGTH = 5
#!/usr/bin/env python
"""
A script to serialize and deserialize Binary Trees in Python
"""
class Node(object):
def __init__(self, val, left=None, right=None):
self.val = val
self.left = left
@damzam
damzam / transform_word.py
Created August 18, 2014 00:04
Find a path from one word to another
#!/usr/bin/env python
"""
Given the start word and end word find one of the
shortest possible paths from one word to the other
that can be achieved by substituting a single
character (where each word in the path is a valid
English word)
Usage:
@damzam
damzam / simple_db.py
Created August 13, 2014 02:13
A Redis-like in-memory database
#!/usr/bin/env python
"""
This is my solution to the Simple Database problem posted on:
http://www.thumbtack.com/challenges/software-engineer
Candidate: David Morton
Email: dcmorton@gmail.com
Usage:
@damzam
damzam / jumble_it_up.py
Last active August 29, 2015 14:04
solve a word jumble
#!/usr/bin/env python
"""
A script that generates all possible words that can be formed from
the characters in a provided string.
Matches are case-insensitive and the wordlist used is obtained from:
https://raw.githubusercontent.com/mattt/mobius/master/data/english-wordlist
Usage: