Skip to content

Instantly share code, notes, and snippets.

View MartinThoma's full-sized avatar

Martin Thoma MartinThoma

View GitHub Profile
#!/usr/bin/python
# -*- coding: utf-8 -*-
class Stack(list):
def __init__(self):
self.push = self.append
def evaluateResult(op1, op2, operator):
if operator == '+':
return op1 + op2
@MartinThoma
MartinThoma / createRandomMatrix.py
Created August 7, 2012 09:42
Create a small random matrix for practicing matrix calculations (jordan normal form)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import random, pprint, numpy
def numpyMatrixToWolframAlpha(A):
"""
Convert the represenation to one that Wolfram|Alpha accepts
"""
string = "{"
for i, line in enumerate(A):
#!/usr/bin/python
# -*- coding: utf-8 -*-
nodes = [float(i) for i in xrange(1,11)]
print nodes
for i in xrange(0,4000):
newList = []
for index in xrange(0,10):
if index == 0:
newList.append((nodes[0]+nodes[1])/2)
.data
.text
.globl main
main: la $t0, a # $t0 = &a[0]
li $a0, 1 # mul=1
li $a1, 0 # i=1
li $a3, 100 # $a3=100
loop: li $t0, 4 # $t0 = 4
mult $a1, $t0 # $lo = i*4
mflo $a2 # $a2 = $lo
@MartinThoma
MartinThoma / schiebe.py
Last active December 15, 2015 15:49
Implementierung der Schiebe-Addiere-Methode
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def niceRepresentation(binaryNumber):
nice = ''
for i, bit in enumerate(binaryNumber):
nice = nice + bit
if i % 4 == 3:
nice += ' '
return nice.strip()
@MartinThoma
MartinThoma / birth.py
Last active December 15, 2015 21:59
Get a feeling for how often it occurs that the oldest person alive died. ``` moose@pc08 ~ $ python birth.py -n 10000 > result.txt moose@pc08 ~ $ cat result.txt Day 1: Yes (Died in age of 70.01 years) Day 2: Yes (Died in age of 70.01 years) Day 3: Yes (Died in age of 70.01 years) Day 4: Yes (Died in age of 70.01 years) Day 25549: Yes (Died in age…
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
""" Another day passes. Some people die, some survive, but everyone gets older.
@param people dead people get removed from this list
@return list of all people who died
"""
def updatePeople(people):
deadAges = []
@MartinThoma
MartinThoma / .vimrc
Created April 9, 2013 14:25
My current .vimrc file.
syntax on " enable syntax highlighting
filetype on " enable file type detection
" Set some nice character listings, then activate list
set list listchars=tab:⟶\ ,trail:·,extends:>,precedes:<,nbsp:%
set list
" 1 tab == 4 spaces
set shiftwidth=4
set tabstop=4
@MartinThoma
MartinThoma / finiteGroupChecks.py
Last active December 16, 2015 23:50
Some checks for finite groups (associativity, commutativity, symmetry of conjunction table) I wanted to check if a symmetric conjunction table implies a commutative group. This is true for groups with 3 elements at maximum and for at least 1,000,000 conjunctions with four elements. At the moment, this has terrible runtime behaviour (it simply br…
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This snippet makes checks on finite algebraic structures. It checks
* associativity
* kommutativity
* neutral element
* inverse elements
def add_attack(d, w, e, s):
attacks.append((d, w, e, s))
pointset.add(e)
pointset.add(w)
# minval[idx] and maxval[idx] hold the minimum and maximum wall heights on the interval referred to by idx
# interval 0 is the full range of the wall (locations having being converted to indexes so we have locations 0...n only)
# interval 2*i+1 is the left half of interval i, interval 2*i+2 is the right half
# We ignore the end points, so our leaf set of intervals is 0-1, 1-2, 2-3, etc. which do not overlap
@MartinThoma
MartinThoma / findHomomorphisms.py
Created August 27, 2013 13:25
Automatically find all homomorphisms between (Z/nZ, *) and (Z/mZ, *). This can easily be adjusted to find homomorphisms between (Z/nZ, +) and (Z/mZ, +)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def isGroupHomomorphism(phi, group1, group2, verbose=False):
for a, b in product(group1['set'], group2['set']):
inner = group1['operator'](a, b)
outer = group2['operator'](phi(a), phi(b))
if verbose:
print("f(%i) = %i, f(%i) = %i f(%i)=%i=%i" % (a, phi(a), b, phi(b), inner, phi(inner), outer))
if phi(inner) != outer: