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 rotate(n, i): | |
j = 0 | |
s = str(n) | |
while(j < i): | |
s = s[-1] + s[:-1] | |
j += 1 | |
return int(s) | |
def rn(n, m): | |
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 gen_trip(n, p): | |
flag = False | |
trips = [] | |
for i in range(0,11): | |
for j in range(0, 11): | |
for k in range(0, 11): | |
if i + j + k == n: | |
if(max([i,j,k]) - min([i,j,k]) <= 2 and max([i,j,k]) >= p): | |
trips.append([i, j, k]) | |
if(max([i,j,k]) - min([i,j,k]) <= 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
d = {} | |
s1 = "yeqz ejp mysljylc kd kxveddknmc re jsicpdrysi rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd de kr kd eoya kw aej tysr re ujdr lkgc jv" | |
s2 = "aozq our language is impossible to understand there are twenty six factorial possibilities so it is okay if you want to just give up" | |
for ch in range(len(s1)): | |
d[s1[ch]] = s2[ch] | |
f = open("A.in") | |
t = int(f.readline().strip()) | |
for i in range(1,t+1): | |
print "Case #"+ str(i) + ": " + ''.join([(d[ch] if ch in d else ch) for ch in f.readline()]), |
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
# Univariate Batch Gradient Descent - Linear Regression | |
# Derived from Andrew Ng's Lectures on Machine Learning (Lecture 2) | |
# Ameer Ayoub <ameer.ayoub@gmail.com> 2/16/2012 | |
import math | |
import matplotlib.pyplot as plt | |
def pd_sqr_err0(theta0, theta1, x, y): | |
m = len(x) | |
return sum([(1.0/m)*((theta0 + theta1 * x[i]) - y[i]) for i in range(m)]) |
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 PIL import Image | |
import math, os, sys | |
def calculate_seam(im, band_width, middle_bias = True, middle_bias_strength = 2): | |
pix = im.load() | |
size = im.size | |
max_std_dev = 0 | |
max_col = 1 | |
for i in range(band_width, im.size[0]-band_width+1): | |
multiplier = (1-(4*math.sqrt((i-im.size[0]/2)**2)/im.size[0]/2))**middle_bias_strength |
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
name = re.compile(""" | |
('.+')?\s* # nickname (optional, group 1) | |
(([^,']*),)?\s* # last name (optional, group 3) | |
([^\(]+) # first name (required, group 4) | |
(\((\w+)\))? # actor number (optional, group 6) | |
""", re.VERBOSE) | |
acted_in = re.compile(""" | |
"?([^"]*?)"?\s # title (required, group 1) surrounded by quotations if it's a tv show | |
\(((\d+)/?(\w+)?).*?\) # the year (required, group 3), followed by `/ROMAN_NUMERAL` | |
# (optional, group 4) if multiple in same year |
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 sys import argv | |
import re | |
def header_def_name(camelcase): | |
word = "" | |
for ch in camelcase: | |
if ch.isupper() and len(word) > 0: | |
word += "_" | |
word += ch | |
return word.upper() |
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
/* | |
* Copyright 2011 Ameer Ayoub | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | |
* in compliance with the License. You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software distributed under the License | |
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
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
/* Fibonacci Calculation using Matrices | |
* Ameer Ayoub <ameer.ayoub@gmail.com> | |
* Jun 13, 2011 | |
*/ | |
#include <iostream> | |
#include <math.h> | |
using namespace std; | |
const int fib_matrix_size = 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
# Python HTML Linker | |
# Ameer Ayoub <ameer.ayoub@gmail.com> | |
from sys import argv | |
import re | |
def print_usage(script_name): | |
print "usage:", script_name, "target_file template_file source_file0 (source_file1, source_file2, ...)" | |
if __name__ == "__main__": | |
script_name = argv[0] |