Skip to content

Instantly share code, notes, and snippets.

View damzam's full-sized avatar

David Morton damzam

View GitHub Profile
def sort_nuts_and_bolts(nuts, bolts):
"""Sort nuts and bolts in O(N log N) time"""
def sort(nuts, bolts):
if len(nuts) == 0:
return []
lnuts, rnuts, lbolts, rbolts = [], [], [], []
nut = nuts.pop()
bolt = None
for b in bolts:
if b == nut and not bolt:
@damzam
damzam / PrimeStream
Last active December 13, 2015 18:58
#!/usr/bin/env python
from collections import defaultdict
class BaseStream(object):
"""
A utility base class that we'll use to make sure that our
streams' respective popNext() methods make use of Python's
__iter__ magic method
"""