| KevinPluck.net | InvisiCalc | SuDoku Helper | Kakuro Combinations | rotxd.com |
|
Introduction Part 1 Part 2 Part 3 Part 4 Part 5 Part 6 More to come... Please add the factorbothering sub-reddit to your frontpage. |
Factor bothering - Part 2Part 1 resulted in us having a plot of all the factors up to 1000 showing very pretty patterns. As the enigma seems to boil down to the number of factors per integer i.e. a lot of interest is focused on primes that don't have any factors, why don't we have a look at the number of factors each integer has? This Python script plots each integer's factor count: plotFactorCounts.py
import Image, ImageDraw
import os
size = 1001,251
im=Image.new("1",size)
draw=ImageDraw.Draw(im)
draw.rectangle(((0,0),size),1) #set image bg to white
factorFile=open('factors1000.txt','r')
factorCount=0
lineCount=0
for line in factorFile:
factorCount=len(line.split())
if factorCount:
draw.line(((lineCount,250),(lineCount,250-(factorCount*4))),0)
lineCount+=1
factorFile.close()
im.save("factorcount.png","PNG")
Here is the resulting image:
As you can see from the code I multiplied the vertical scale by four. The statistitian in wants to see a histogram of that: plotFactorCountsHistogram.py
import Image, ImageDraw
import os,sys
import math
size = 500,501
im=Image.new("1",size)
draw=ImageDraw.Draw(im)
draw.rectangle(((0,0),size),1) #set image bg to white
factorFile=open(sys.argv[1],'r')
factorHistogram=[0]*500
maxFactorCount=0
for line in factorFile:
factorCount=len(line.split())
factorHistogram[factorCount]+=1
if factorHistogram[factorCount]>maxFactorCount:
maxFactorCount=factorHistogram[factorCount]
factorFile.close()
n=0
verticalScale=500.0/maxFactorCount
for n in range(0,500):
if factorHistogram[n]:
draw.line(((n,500),(n,500-(factorHistogram[n]*verticalScale))),0)
im.save(sys.argv[2],"PNG")
plotFactorCountsHistogram.py factors1000.txt factorsHist1000.png Resulting:
Hmmm... Need MORE data! 10,000,000 oughta do it! factorGenerator.pl 10000000 > factorsTenMill.txtHours later (yes really)... plotFactorCountsHistogram.py factorsTenMill.txt factorsHistTenMill.png
I think I need to shrink the height and apply some non-linear scaling - Log base 10 should do it. plotFactorCountsHistogramLog.py
import Image, ImageDraw
import os,sys
import math
size = 500,251
im=Image.new("1",size)
draw=ImageDraw.Draw(im)
draw.rectangle(((0,0),size),1) #set image bg to white
factorFile=open(sys.argv[1],'r')
factorHistogram=[0]*500
maxFactorCount=0.0
for line in factorFile:
factorCount=len(line.split())
factorHistogram[factorCount]+=1
if factorHistogram[factorCount]>maxFactorCount:
maxFactorCount=factorHistogram[factorCount]
factorFile.close()
n=0
verticalScale=250.0/math.log10(maxFactorCount)
for n in range(0,500):
if factorHistogram[n]:
draw.line(((n,250),(n,250-(math.log10(factorHistogram[n])*verticalScale))),0)
im.save(sys.argv[2],"PNG")
plotFactorCountsHistogramLog.py factorsTenMill.txt factorsLogHistTenMill.png
Of course, there will be no odd factor counts so let's plot every second count and halve the height again: plotFactorCountsHistogramLogHalf.py
import Image, ImageDraw
import os,sys
import math
size = 250,126
im=Image.new("1",size)
draw=ImageDraw.Draw(im)
draw.rectangle(((0,0),size),1) #set image bg to white
factorFile=open(sys.argv[1],'r')
factorHistogram=[0]*500
maxFactorCount=0.0
for line in factorFile:
factorCount=len(line.split())
factorHistogram[factorCount]+=1
if factorHistogram[factorCount]>maxFactorCount:
maxFactorCount=factorHistogram[factorCount]
factorFile.close()
n=0
verticalScale=(size[1]-1)/math.log10(maxFactorCount)
for n in range(0,500,2):
if factorHistogram[n]:
draw.line(((n/2,size[1]-1),(n/2,size[1]-1-(math.log10(factorHistogram[n])*verticalScale))),0)
im.save(sys.argv[2],"PNG")
That's a little clearer. So what have we ended up with? To my monkey brain there looks like some multiple populations in there, or is it Pareidolia?
Is the fact that there are no integers with 60 factors significant in the first 10 million? Is there even a pattern here? Will adding more integers to the analysis simply fill it all in? |