Skip to content

Instantly share code, notes, and snippets.

# Euler project problem 17
words = ['', 'one', 'two', 'three', 'four','five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']
debug = 0
def build_word(n):
# --debug
@khafatech
khafatech / gist:58553
Created February 5, 2009 04:55
Huffman Code
"Calculates the binary huffman code for the given characters and their frequencies."
from copy import copy
freqs = {'a': 20, 'b': 10, 'c': 12, 'd': 5, 'e': 15, 'z': 65 }
class Node:
def __init__(self, ch='', freq=-1, code=None):
elements = ['FINDING_ID', 'FINDING_STATUS', 'FINDING_DETAILS', 'SCRIPT_RESULTS', 'TOOL', 'TOOL_VERSION', 'AUTHENTICATED_FINDING', 'GD_VUL_NAME', 'GD_SEVERITY']
def process_finding(finding):
global elements
d = {}
for element in elements:
result = finding.getElementsByTagName(element)
# Element dne
"""
Generate graph of prerequisites.
http://www.csupomona.edu/~cs/student/undergrad.shtml
"""
import urllib
import re
data = urllib.urlopen('http://www.csupomona.edu/~cs/student/undergrad.shtml').read()
digraph classes {
cs490;
cs299;
cs130;
cs375;
cs241 -> cs311;
cs264 -> cs408;
cs311 -> cs408;
cs400;
import re
import os
import glob
fnames = glob.glob('*.flac')
# encode files
for f in fnames:
// copy constructor
Matrix::Matrix(const Matrix &rhs)
{
if (this != &rhs) {
// newly created object
this->a = NULL;
// copy rhs to this
*this = rhs;
# Euler 184
import math
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
import math
radius = 105
width = (radius * 2) - 1
points = []
for x in xrange(-radius, radius+1):
for y in xrange(-radius, radius+1):
import sys
import math
if len(sys.argv) > 1:
radius = int(sys.argv[1])
else:
radius = 5