Skip to content

Instantly share code, notes, and snippets.

View cvrebert's full-sized avatar

Chris Rebert cvrebert

View GitHub Profile
@cvrebert
cvrebert / pokecrack.py
Created January 19, 2012 02:54
So, I took CSE 127...
#!/usr/bin/env python
# Background: http://cses.ucsd.edu/pokemon/ & http://cseweb.ucsd.edu/classes/fa11/cse127-a/
from urllib import urlopen, urlencode
url = "http://cses.ucsd.edu/pokemon/submitemail.php"
for n in range(1, 1000):
data = urlencode({"email":"[email protected]", "pokemonid":str(n), "submit":"Catch!"})
f = urlopen(url, data)
result = f.read()
f.close()
print(result) # if you want
@cvrebert
cvrebert / balls_in_numbered_boxes_CVR.py
Created September 11, 2011 02:11
Refactored "recursive algorithm for balls in numbered boxes"
def balls_in_numbered_boxes(balls, box_sizes):
if not isinstance(balls, int):
raise TypeError("balls must be a non-negative integer.")
if balls < 0:
raise ValueError("balls must be a non-negative integer.")
box_sizes = list(box_sizes)
if not box_sizes:
raise ValueError("box_sizes must be a non-empty iterable.")