Skip to content

Instantly share code, notes, and snippets.

Martin Thoma MartinThoma

Block or report user

Report or block MartinThoma

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@MartinThoma
MartinThoma / countingSort.py
Created May 16, 2012
Counting Sort implemenatation
View countingSort.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
def countingSort(A, k):
"""
Implementation of counting sort.
@param A: the list of integers which should get sorted.
No element should be smaller than 1
@param k: the highest number in A
"""
View sumOfDigitsHash.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
from math import log, ceil
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.mlab as mlab
try:
@MartinThoma
MartinThoma / multiply.py
Created Jun 17, 2012
How multiplication works
View multiply.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
""" How multiplication works """
def simple(a, b):
""" Multiplication you've learned at school """
additions = 0
multiplications = 0
product = 0
View createRandomGraph.cpp
#include <iostream>
#include <vector>
#include <iterator>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#define DIRECTED true
#define MULTIPLE_EDGES false
@MartinThoma
MartinThoma / quicksort.py
Created Jun 30, 2012
Python implementation of QuickSort for testing purposes.
View quicksort.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
comparisons = 0
switches = 0
calls = 0
def read(filename):
lines = open(filename, 'r').read().splitlines()
return map(int, lines)
@MartinThoma
MartinThoma / choleskyWikiWrong.py
Created Jul 2, 2012
Cholesky-Zerlegung in Wikipedia oldid=104368978
View choleskyWikiWrong.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
def choleskyDecomposition(A):
"""
@param A: a nested list which represents a symmetric,
positiv definit n x n matrix.
@return: False if it didn't work, otherwise the matrix G
"""
n = len(A)
@MartinThoma
MartinThoma / choleskyBanachiewicz.py
Created Jul 2, 2012
Implementation of the algorithm of Banachiewicz for Cholesky-Decomposition
View choleskyBanachiewicz.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
def choleskyBanachiewicz(A):
"""
@param A: a nested list which represents a symmetric,
positiv definit n x n matrix.
@return: False if it didn't work, otherwise the matrix G
"""
n = len(A)
@MartinThoma
MartinThoma / getBinary.py
Created Jul 3, 2012
Takes a number and a number of bits and returns a True-False representation of the number with bits bits.
View getBinary.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
def getBinary(number, bits):
""" Takes a number and a number of bits and returns a True-False
representation of the number with bits bits.
@param number: The number you want to convert
@param bits: The number of bits
@return a list of True / False values
"""
@MartinThoma
MartinThoma / btree.py
Created Jul 22, 2012 — forked from teepark/btree.py
a pure-python B tree implementation
View btree.py
import bisect
import itertools
import operator
class _BNode(object):
__slots__ = ["tree", "contents", "children"]
def __init__(self, tree, contents=None, children=None):
self.tree = tree
self.contents = contents or []
@MartinThoma
MartinThoma / mult-add.py
Created Aug 2, 2012
Test how fast multiplication and addition is.
View mult-add.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
This script shows that addition and multiplication is similar
in terms of execution speed.
"""
import random, datetime
You can’t perform that action at this time.