Skip to content

Instantly share code, notes, and snippets.

View anirudhjayaraman's full-sized avatar
🏠
Working from home

Anirudh Jayaraman anirudhjayaraman

🏠
Working from home
View GitHub Profile
@anirudhjayaraman
anirudhjayaraman / euler13.txt
Created September 1, 2015 07:14
Problem Matrix for Project Euler Problem 13
37107287533902102798797998220837590246510135740250
46376937677490009712648124896970078050417018260538
74324986199524741059474233309513058123726617309629
91942213363574161572522430563301811072406154908250
23067588207539346171171980310421047513778063246676
89261670696623633820136378418383684178734361726757
28112879812849979408065481931592621691275889832738
44274228917432520321923589422876796487670272189318
47451445736001306439091167216856844588711603153276
70386486105843025439939619828917593665686757934951
@anirudhjayaraman
anirudhjayaraman / euler13.py
Created September 1, 2015 07:18
Project Euler Problem 13
# Read the problem matrix into an array in python
filename = 'euler13.txt'
with open(filename, "r") as ins:
array = []
for line in ins:
array.append(line)
# Convert the array into an array of integers
newArray = []
for i in array:
newArray.append(int(i))
@anirudhjayaraman
anirudhjayaraman / euler14.py
Created September 1, 2015 16:07
Project Euler Problem 14 - naive method
# Longest Collatz Sequence under a million
# Function listing collatz sequence for a number
def collatz(n):
"function listing collatz sequence for a positive integer"
coll = []
coll.append(n)
while n != 1:
if n % 2 == 0:
n = n/2
coll.append(n)
@anirudhjayaraman
anirudhjayaraman / euler14.py
Created September 1, 2015 16:11
Project Euler Problem 14 - Smart Method
collatz = {1:1}
def Collatz(n):
global collatz
if not collatz.has_key(n):
if n%2 == 0:
collatz[n] = Collatz(n/2) + 1
else:
collatz[n] = Collatz(3*n + 1) + 1
return collatz[n]
@anirudhjayaraman
anirudhjayaraman / euler18.txt
Created September 5, 2015 07:30
Project Euler Problem 18 Triangle Array
75
95 64
17 47 82
18 35 87 10
20 04 82 47 65
19 01 23 75 03 34
88 02 77 73 07 63 67
99 65 04 28 06 16 70 92
41 41 26 56 83 40 80 70 33
41 48 72 33 47 32 37 16 94 29
@anirudhjayaraman
anirudhjayaraman / euler67.txt
Created September 5, 2015 07:43
Project Euler Problem 67 Triangle Array
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
@anirudhjayaraman
anirudhjayaraman / euler67.py
Created September 5, 2015 08:11
Project Euler Problem 67
# 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(' ')
@anirudhjayaraman
anirudhjayaraman / euler68.py
Created September 13, 2015 12:32
Project Euler Problem 68
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)]
@anirudhjayaraman
anirudhjayaraman / sloc.py
Created September 27, 2015 09:32
Count Source Lines of Code in Python
# 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):
@anirudhjayaraman
anirudhjayaraman / choroplethr.R
Created October 2, 2015 02:51
Choropleths in R
## 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