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 / 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):
@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 / 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 / tutorial.md
Last active August 29, 2015 14:02
Short Markdown Tutorial

Here's how to do markdown :) Note that you can look at the raw source of this document, which is here

To embed a link, you can simply put something like this in a file:

[This links to mtzionsmarr.com](http://mtzionsmarr.com)

and it renders like this: This links to mtzionsmarr.com

To do headers and what not, you can precede a line with a hash:

/*!
*
* welcome to wavepot
* ------------------
*
* this is a live editor. you create a function named `dsp`
* that accepts the parameter `t`, the coefficient of time,
* which you use to generate a single sample (range -1..1)
*
@chipbell4
chipbell4 / sortme.py
Created August 22, 2014 02:22
My (untested) solution for Sort Me Practice 8/21/2014
# Note: This is NOT tested!
# There's a constant in Python for this, but I couldn't remember
ABC = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def getWordList(length):
words = []
for i in range(length):
words.append(input().strip())
return words
@chipbell4
chipbell4 / digit.py
Created August 22, 2014 02:30
My Solution For Digit Sum (Still buggy) for Practice 8/21/2014
def buildDigits(digit_list):
# sort the digit list
# TODO: Here's where the bug is. Because the 0's get pushed to the front of the list, I put 0's at the beginning of numbers.
# What would need to happen is potentially a sort, and then pushing 0's back in the list a couple spaces?
digit_list.sort(reverse = True)
summands = ['', '']
# Here's the basic idea for the algorithm: Sort the digits, then divide them equally (in sorted order) among two strings
@chipbell4
chipbell4 / pages.py
Created August 22, 2014 02:36
My Missing Pages solution (Practice 8/21/2014)
def pagesTaken(N, P):
original_p = P
# adjust P to be less than N/2
if P > N/2:
P = N - P + 1
# if even, move back a page
if P % 2 == 0:
P -= 1
@chipbell4
chipbell4 / ken.py
Last active August 29, 2015 14:09
Ken Ken Solution
def memoize(func):
hashed_states = {}
def memoized_func(*args):
if args not in hashed_states:
hashed_states[args] = func(*args)
return hashed_states[args]
return memoized_func
@chipbell4
chipbell4 / generateKenKenJudging.py
Created November 9, 2014 20:53
Judge Input Generator for the Ken Ken Problem
import sys
n_max = int(sys.argv[1])
k_max = int(sys.argv[2])
c_max = int(sys.argv[3])
print(n_max * k_max * c_max)
for n in range(1, n_max + 1):
for k in range(1, k_max + 1):
for c in range(1, c_max + 1):