Skip to content

Instantly share code, notes, and snippets.

@pichenettes
Created November 16, 2012 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pichenettes/4090053 to your computer and use it in GitHub Desktop.
Save pichenettes/4090053 to your computer and use it in GitHub Desktop.
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