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
# Boyer Moore String Search implementation in Python | |
# Ameer Ayoub <[email protected]> | |
# Generate the Bad Character Skip List | |
def generateBadCharShift(term): | |
skipList = {} | |
for i in range(0, len(term)-1): | |
skipList[term[i]] = len(term)-i-1 | |
return skipList |
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
# BunchO Sorting Algorithms | |
# Ameer Ayoub <[email protected]> | |
# Last Modified 12/2/2010 | |
import random | |
# | |
# Insertion Sort | |
# | |
def insertion_sort(l): | |
"""Given an input list, returns a sorted permutation of the list |
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
# Order Statistics | |
# Ameer Ayoub <[email protected]> | |
import random, copy | |
# From quicksort | |
# Nonrandomized Pivot | |
def partition(l, p, q, pivot=None): | |
r = copy.copy(l) | |
if pivot: | |
r[pivot], r[p] = r[p], r[pivot] |
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 euler39brute(): | |
sum_count = [0] * 1001 | |
for a in range(2000/3 + 1): | |
if a%100 == 0: | |
print "|", | |
for b in range(a+1): | |
for c in range(a+1,1001-a-b): | |
if a**2 + b**2 == c**2: | |
sum_count[a+b+c] += 1 | |
return sum_count.index(max(sum_count)) |
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 fractions import gcd | |
def euler39betterorworse(): | |
sum_count = [0] * 1001 | |
triples_to_check = [] | |
for a in range(2000/3): | |
if a%100 == 0: | |
print "|", | |
for b in range(a+1): | |
for c in range(a+1,1001-a-b): |
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 fractions import gcd | |
def euler39better2(): | |
sum_count = [0] * 1001 | |
triples_to_check = [] | |
for a in range(2000/3): | |
if a%100 == 0: | |
print "|", | |
for b in range((a%2)+1, a+1, 2): | |
for c in range(a+1,1001-a-b): |
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 fractions import gcd | |
def euler39optimized(): | |
sum_count = [0] * 1001 | |
y = 2 | |
while y**2 <= 500: | |
for z in [x for x in range(y) if gcd(y, x) == 1]: | |
a = y**2 - z**2 | |
b = 2*y*z | |
c = y**2 + z**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
# increment_version_num.py | |
# Utility to incremement version number in drupal info files | |
# Ameer Ayoub <[email protected]> | |
import re, sys, os | |
major_v = 0 | |
minor_v = 0 | |
def inc_dv_num(s, minor = True): | |
global major_v, minor_v |
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/sh | |
echo updating version numbering... | |
python inc_v_num.py --file content_reservation.info |
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 <[email protected]> | |
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] |
OlderNewer