Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bit shifting fractal function of death
import numpy
import pylab
def f(n, bit):
if bit == 0:
return n
else:
if n & (1 << bit):
return f(n % (1 << bit), bit - 1) + (n & (1 << (bit - 1)))
else:
return f(n % (1 << bit), bit - 1)
graph = numpy.zeros((4095, 1))
for i in xrange(4095):
graph[i] = f(i, 11)
pylab.plot(graph, '+')
pylab.savefig('foo.pdf')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment