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 / withNumPy.py
Last active October 29, 2015 22:47
Manipulating Lists with NumPy
import pylab
import numpy as np
def loadFile():
inFile = open('julyTemps.txt')
high = [];vlow = []
for line in inFile:
fields = line.split()
if len(fields) != 3 or 'Boston' == fields[0] or 'Day' == fields[0]:
continue
@anirudhjayaraman
anirudhjayaraman / withoutNumPy.py
Last active October 22, 2015 08:12
List Manipulation Without NumPy
import pylab
def loadfile():
inFile = open('julyTemps.txt', 'r')
high =[]; low = []
for line in inFile:
fields = line.split()
if len(fields) < 3 or not fields[0].isdigit():
pass
else:
@anirudhjayaraman
anirudhjayaraman / julyTemps.txt
Created October 22, 2015 08:15
July Temperatures: Highs and Lows
Boston July Temperatures
-------------------------
Day High Low
------------
1 91 70
2 84 69
3 86 68
4 84 68
@anirudhjayaraman
anirudhjayaraman / countInversions.py
Created October 23, 2015 13:29
Counting the Number of Inversions In An Array
# 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
@anirudhjayaraman
anirudhjayaraman / sherlockandthebeast.py
Created December 12, 2015 01:49
Solution to HackerRank Problem - Sherlock and the Beast
#!/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
@anirudhjayaraman
anirudhjayaraman / permMatrices.m
Created December 14, 2015 08:29
Create a list of permuation matrices in Octave / Matlab
% function to generate permutation matrices given the size of the desired permutation matrices
function x = permMatrices(n)
x = zeros(n,n,factorial(n));
permutations = perms(1:n);
for i = 1:size(x,3)
x(:,:,i) = eye(n)(permutations(i,:),:);
end
endfunction
@anirudhjayaraman
anirudhjayaraman / output13b.txt
Created December 14, 2015 12:15
Output to 13B
m =
ans(:,:,1) =
0 1 0 0
0 0 1 0
1 0 0 0
0 0 0 1
ans(:,:,2) =
@anirudhjayaraman
anirudhjayaraman / output13a.txt
Created December 14, 2015 13:18
Output to 13(a)
ans(:,:,1) =
0 1 0
0 0 1
1 0 0
ans(:,:,2) =
0 0 1
1 0 0
@anirudhjayaraman
anirudhjayaraman / Section2_7_13.m
Created December 14, 2015 15:34
Solution to Problem 13, Section 2.7 Linear Algebra (Gilbert Strang)
% Solution for part (a)
p = permMatrices(3);
n = size(p,3); % number of permutation matrices
v = zeros(n,1); % vector of zeros with dimension equalling number of permutation matrices
% check for permutation matrices other than identity matrix with 3rd power equalling identity matrix
for i = 1:n
if p(:,:,i)^3 == eye(3)
v(i,1) = 1;
end
end
@anirudhjayaraman
anirudhjayaraman / introduction.R
Last active December 17, 2015 06:51
Code from the 1st section of Datacamp's course on Data Manipulation in R with dplyr
# INTRODUCTION TO dplyr AND tbls
# Load the dplyr package
library(dplyr)
# Load the hflights package
library(hflights)
# Call both head() and summary() on hflights
head(hflights)
summary(hflights)