Sunday, April 30, 2017

Interesting Plot Snippet: Bitwise Or and Addition Operation

If the sum and the result of bitwise or operation of two numbers are the same, plotting these numbers in a scatter diagram produces a beautiful shape.

import matplotlib.pyplot as plt

l1 = []
l2 = []
for i in xrange(1000):
 for j in xrange(1000):
  if (i + j) == (i | j):
   l1.append(i)
   l2.append(j)

plt.scatter(l1,l2)
plt.show()

This is the figure that comes up:


No comments:

Post a Comment