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
#!/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 |
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
#!/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): |
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
#!/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) |
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
.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 |
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
#!/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() |
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
#!/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 = [] |
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
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 |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
This snippet makes checks on finite algebraic structures. It checks | |
* associativity | |
* kommutativity | |
* neutral element | |
* inverse elements |
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 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 |
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
#!/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: |