Created
November 16, 2012 19:18
-
-
Save pichenettes/4090053 to your computer and use it in GitHub Desktop.
Bit shifting fractal function of death
This file contains hidden or 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 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