Skip to content

Instantly share code, notes, and snippets.

@cavedave
Created October 31, 2017 13:49
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 cavedave/672b50e278351b77eb83ea0abfea2a0a to your computer and use it in GitHub Desktop.
Save cavedave/672b50e278351b77eb83ea0abfea2a0a to your computer and use it in GitHub Desktop.
Heatmap of the prime numbers. And of the prime numbers except the least significant digit http://liveatthewitchtrials.blogspot.ie/2017/10/yet-more-prime-pictures.html
#!/usr/bin/python3
import numpy as np
#the number of digits to use
numDigits = 60000000
y=450;
a = np.zeros( (10,10) )
previous=0
currentPrime=0
def getDigits():
#0.12345678910111213…
current = 1;
print(current)
while True:
current_str = str(current);
for digit in current_str:
yield int(digit)
current = current + 1
def getPrimeDigits():
#0.12345678910111213…
current = 1;
global currentPrime
newP =next_prime(current)
# print(newP)
while True:
newP =next_prime(current)
#print(newP)
current_str = str(newP);
current_str = current_str[:-1]#strip last digit to see if lack of 2,4,6,8,0 causes all issue
currentPrime =newP
for digit in current_str:
yield int(digit)
current = current + 1
gen = getPrimeDigits()
for i in range(numDigits):
previous = digit-1
digit = next(gen)
a[digit-1,previous]+=1
i=i+1
print(currentPrime)
a
import matplotlib.pyplot as plt
import numpy as np
plt.imshow(a, cmap='bwr', interpolation='nearest')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment