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
def quicksort(x): | |
if len(x) == 1 or len(x) == 0: | |
return x | |
else: | |
pivot = x[0] | |
i = 0 | |
for j in range(len(x)-1): | |
if x[j+1] < pivot: | |
x[j+1],x[i+1] = x[i+1], x[j+1] | |
i += 1 |
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
def karatsuba(x,y): | |
"""Function to multiply 2 numbers in a more efficient manner than the grade school algorithm""" | |
if len(str(x)) == 1 or len(str(y)) == 1: | |
return x*y | |
else: | |
n = max(len(str(x)),len(str(y))) | |
nby2 = n / 2 | |
a = x / 10**(nby2) | |
b = x % 10**(nby2) |
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
# set working directory to local directory where the data is kept | |
setwd("~/IGIDR/Development Economics - MIT/Homework Assignment 01") | |
# read the data | |
wb_dev_ind = read.csv("wb_dev_ind.csv") | |
# summarize data | |
summary(wb_dev_ind) | |
# Question 1 | |
# What is the Mean of GDP per capita? What is the standard deviation of GDP per capita? |
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
procedure karatsuba(num1, num2) | |
if (num1 < 10) or (num2 < 10) | |
return num1*num2 | |
/* calculates the size of the numbers */ | |
m = max(size_base10(num1), size_base10(num2)) | |
m2 = m/2 | |
/* split the digit sequences about the middle */ | |
high1, low1 = split_at(num1, m2) | |
high2, low2 = split_at(num2, m2) | |
/* 3 calls made to numbers approximately half the size */ |
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
#!/bin/python | |
import sys | |
def combinations_sum(n): | |
k = n/2 | |
combs = [] | |
answers = [] | |
for i in range(0,k+1): | |
a,b = i, n-i |
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
# load contents of text file into a list | |
# numList | |
NUMLIST_FILENAME = "IntegerArray.txt" | |
inFile = open(NUMLIST_FILENAME, 'r') | |
with inFile as f: | |
numList = [int(integers.strip()) for integers in f.readlines()] | |
count = 0 |
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
def merge_tuple(a,b): | |
""" Function to merge two arrays of tuples """ | |
c = [] | |
while len(a) != 0 and len(b) != 0: | |
if a[0][0] < b[0][0]: | |
c.append(a[0]) | |
a.remove(a[0]) | |
else: | |
c.append(b[0]) | |
b.remove(b[0]) |
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
# Set working directory to local directory where the data is kept | |
setwd("~/IGIDR/Development Economics - MIT/Homework Assignment 02") | |
# read data | |
migueldata = read.csv("ted_miguel_worms.csv", header = TRUE) | |
attach(migueldata) | |
# Question 6 | |
# How many observations are there per pupil? (Enter a whole number of 0 or higher)? | |
length(migueldata$pupid) | |
length(unique(migueldata$pupid)) | |
# Question 7 |
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
### Linear Regression Using lm() ---------------------------------------- | |
data("swiss") | |
dat <- swiss | |
linear_model <- lm(Fertility ~ ., data = dat) | |
summary(linear_model) | |
# Call: | |
# lm(formula = Fertility ~ ., data = dat) | |
# |
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 Vertex: | |
def __init__(self, vertex): | |
self.name = vertex | |
self.neighbors = [] | |
def add_neighbor(self, neighbor): | |
if isinstance(neighbor, Vertex): | |
if neighbor.name not in self.neighbors: | |
self.neighbors.append(neighbor.name) | |
neighbor.neighbors.append(self.name) |
NewerOlder