This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Here's what the linked list looks like. | |
// I've assumed int values, so you can see that it works | |
class Node | |
{ | |
public: | |
Node() : next(NULL), value(0) {} | |
Node(int v) : next(NULL), value(v){} | |
Node* next; | |
int value; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node | |
{ | |
public: | |
Node() : next(NULL), value(0) {} | |
Node(int v) : next(NULL), value(v){} | |
Node* next; | |
int value; | |
}; | |
bool detect_loop(Node* head) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float root(float n, float epsilon=.000001f) | |
{ | |
if (n <= 0.0f) | |
return 0.0f; | |
float guess = n/2.1f; | |
float error = n - guess*guess; | |
while (epsilon < fabs(error)) | |
{ | |
guess += error / 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool find(int* a, int n, int i) | |
{ | |
int lo = 0; | |
int hi = n-1; | |
while (lo <= hi) | |
{ | |
int mid = a[(hi + lo) / 2]; // TODO: Overflow | |
printf("lo: %d, mid: %d, hi: %d\n", lo, mid, hi); | |
if (mid == i) | |
return true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import pi, sin, cos, atan2, sqrt | |
def haversine_distance(loc1, loc2): | |
"""Haversine formula - give coordinates as (lat_decimal, lon_decimal) tuples. Returns distance in miles""" | |
earth_radius = 6371.0 # km | |
to_radians = lambda x : x * pi / 180.0 | |
lat1, lon1 = map(to_radians, loc1) | |
lat2, lon2 = map(to_radians, loc2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def to_wordle(s): | |
f = open(s) | |
g = open('wordle.txt', 'w') | |
for line in f: | |
token, count = line.strip().split('\t') | |
g.write('%s: %s\n' % (token, count)) | |
f.close() | |
g.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from http://en.wikipedia.org/wiki/Category:Shades_of_blue | |
blues = {'Air Force': '#5D8AA8', | |
'Alice': '#F0F8FF', | |
'Ao': '#0000BB', | |
'Azure': '#007FFF', | |
'Baby': '#89CFF0', | |
'Bleu de France': '#318CE7', | |
'Blue': '#0000FF', | |
'Bondi': '#0095B6', | |
'Brandeis': '#0070FF', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE sqf_2010 | |
( | |
id serial, | |
year text, | |
pct text, | |
ser_num text, | |
datestop text, | |
timestop text, | |
recstat text, | |
inout text, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
double root_NR(double n, double epsilon=.0000000001) | |
{ | |
if (n < 0) return 0.0; // throw? | |
// http://mathworld.wolfram.com/SquareRootAlgorithms.html | |
// Both Bhaskara-Brouncker and Newton's iteration use | |
// (1 + n) / 2 instead of just guessing n/2. | |
double r = 0.5 + 0.5 * n; | |
double f = r*r - n; | |
while (epsilon < abs(f)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// code taken from here: | |
// http://www.analogpixel.org/blog/2011/09/13/msced-148-boxy-lady-take-2/#more-764 | |
// and formatted for readability. | |
PImage pic1; | |
PGraphics pg; | |
boolean grow; | |
int box_size; | |
int MAXS = 40; | |
int MINS = 1; |