Skip to content

Instantly share code, notes, and snippets.

View chipbell4's full-sized avatar
๐Ÿ‘Š
KAMPUTORS!

Chip Bell chipbell4

๐Ÿ‘Š
KAMPUTORS!
View GitHub Profile
@chipbell4
chipbell4 / dido.py
Created March 15, 2014 21:06
My Solution For Queen Dido
def max_area(L):
L.sort()
left, right = 0,0
while len(L) > 0:
# if the left is shorter, put the twig over there
if left < right:
left += L.pop()
# if the right is shorter, put it on the right
@chipbell4
chipbell4 / memoize.py
Created March 15, 2014 20:42
A simple function to wrap a recursive function to make it memoize.
def memoize(F):
# A hash table for storing previous states
hashed_states = {}
def memoized_F(*args):
# if we haven't memoized this state, calculate
# it. Then return it
if args not in hashed_states:
hashed_states[args] = F(*args)
@chipbell4
chipbell4 / typecheck.py
Created March 15, 2014 20:33
A Python Decorator for type-checking function args, similar in vein to PHP type-hinting
class typecheck:
def __init__(self, *args):
self.types = args
def __call__(self, F):
# create a new function that checks
# the function types first
def typechecked_F(*args):
for expected_type, arg in zip(self.types, args):