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
import random | |
def to_base(n, b): | |
""" Converts n to a string in base b. """ | |
if n == 0: return '0' | |
l = [] | |
while n: | |
l.append(chr((n % b) + ord('0'))) | |
n /= b | |
l.reverse() |
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
# SOURCE: http://elonen.iki.fi/code/misc-notes/python-gaussj/ | |
def gauss_jordan(m, eps = 1.0/(10**10)): | |
"""Puts given matrix (2D array) into the Reduced Row Echelon Form. | |
Returns True if successful, False if 'm' is singular. | |
NOTE: make sure all the matrix items support fractions! Int matrix will NOT work! | |
Written by Jarno Elonen in April 2005, released into Public Domain""" | |
(h, w) = (len(m), len(m[0])) | |
for y in range(0,h): | |
maxrow = y | |
for y2 in range(y+1, h): # Find max pivot |