Skip to content

Instantly share code, notes, and snippets.

@fcostin
fcostin / quine_1.py
Created March 18, 2010 04:57
first attempt at a python3 quine
b = ['b = ', "print('%s' % str(x[0]), end='')", '\n', 'def f(*x): eval(b[1]) if type(x[0]) is str else [g(s) for s in x]', "def g(x): print('f(b[%d])' % x if type(x) is int else 'f(%s)' % x)", "0, 'b', 4, 2, 3", '2, b[5], b[6]']
def g(x): print('f(b[%d])' % x if type(x) is int else 'f(%s)' % x)
def f(*x): eval(b[1]) if type(x[0]) is str else [g(s) for s in x]
f(b[0])
f(b)
f(b[4])
f(b[2])
f(b[3])
f(b[2])
f(0, 'b', 4, 2, 3)
@fcostin
fcostin / numpy_bug.py
Created March 12, 2010 00:58
bug in numpy 1.2.1
# leads to a segfault in version 1.2.1
import numpy
bad = (numpy.array([0]), numpy.array(0))
numpy.asarray(bad)
import cmepy.solver
def do_something_fancy(y):
"""
transforms the solution y in some interesting and useful manner
"""
return y # TODO IMPLEMENT ME
class FancySolver(object):
def to_sparse(p_dense):
states = numpy.indices(numpy.shape(p_dense))
p_sparse = {}
for state in states.transpose():
state = tuple(state)
probability = p_dense[state]
if probability > 0:
p_sparse[state] = p_dense[state]
return p_sparse