This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
| [1] "The number of solutions are:" | |
| [1] 128 | |
| [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] | |
| solution 9 1 2 5 6 7 3 4 8 | |
| solution 7 9 6 1 5 2 3 4 8 | |
| solution 1 9 6 7 5 2 3 4 8 | |
| solution 1 5 2 3 4 8 7 9 6 | |
| solution 1 5 2 3 4 8 9 7 6 | |
| solution 5 1 2 9 6 7 3 4 8 | |
| solution 5 1 2 9 6 7 4 3 8 |
This file contains hidden or 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
| ## The problem could be written as u + 13v/w + x + 12y - z - 11 + pq/r -10 = 66 | |
| ## which reduces to u + 13v/w + x + 12y - z + pq/r = 87 | |
| ## This problem was solved on [1] "Wed May 27 17:46:52 2015" | |
| baoloc <- function() | |
| { | |
| packages <- rownames(installed.packages()) | |
| if("combinat" %in% packages) library("combinat") else install.packages("combinat") | |
| numbers <- 1:9 | |
| permutations <- permn(numbers) ## list of all permutations of vector input |
This file contains hidden or 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 the requisite libraries into R | |
| library("xlsx") | |
| library("choroplethr") | |
| library("choroplethrAdmin1") | |
| library("ggplot2") | |
| indianregions <- get_admin1_regions("india") | |
| ## gets dataframe of 2 columns with name of country ("india") throughout column 1 | |
| ## and name of regions in 2nd column |
This file contains hidden or 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
| # prints recursive count of lines of python source code from current directory | |
| # includes an ignore_list. also prints total sloc | |
| import os | |
| cur_path = os.getcwd() | |
| ignore_set = set(["__init__.py", "count_sourcelines.py"]) | |
| loclist = [] | |
| for pydir, _, pyfiles in os.walk(cur_path): |
This file contains hidden or 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 itertools import permutations | |
| from itertools import combinations | |
| # array of candidate solutions empty at the beginning | |
| record = [] | |
| # choose 5 numbers for inner cells between 1 and 9; there are 9C5 combinations | |
| # the problem ask for a 16-digit number, so 10 is not to be included in inner cells | |
| cells = range(1,10) | |
| inner_cells = [map(int,comb) for comb in combinations(cells,5)] |
This file contains hidden or 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
| # Read the problem matrix into a triangle array in python | |
| filename = 'euler67.txt' | |
| with open(filename, "r") as ins: | |
| array = [] | |
| for line in ins: | |
| array.append(line) | |
| # Convert the triangle arry entries into integers | |
| newArray = [] | |
| for i in array: | |
| j = i.split(' ') |
This file contains hidden or 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
| 59 | |
| 73 41 | |
| 52 40 09 | |
| 26 53 06 34 | |
| 10 51 87 86 81 | |
| 61 95 66 57 25 68 | |
| 90 81 80 38 92 67 73 | |
| 30 28 51 76 81 18 75 44 | |
| 84 14 95 87 62 81 17 78 58 | |
| 21 46 71 58 02 79 62 39 31 09 |