| 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 3This is a bit of a digression as I have just thought of a nice way of picturing factors and their primes, I'm certainly not claiming this as an original thought though! As two factors are multiplied together to become an integer you can think that that would represent the area of a rectangle. A prime would be an area that can only be represented in a rectangle with one of its sides having the length of one.
(Justification for having 1 as a prime perhaps?) This means we could plot all the factors out in two dimensions, maybe we can see more pretty patterns!
I might try just plotting one pixel in the top right corner of each rectangle. plotFactorRectangles.py
import Image, ImageDraw import os,sys import math size = 1000,101 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') intLineCount=0 for line in factorFile: intLineCount+=1 arrFactors=line.split() intFactorArrayLength=len(arrFactors) if intFactorArrayLength>0: for n in range(0,intFactorArrayLength-1,2): im.putpixel((int(arrFactors[n+1]),100-int(arrFactors[n])),0) else: im.putpixel((intLineCount,99),0) factorFile.close() im.save(sys.argv[2],"PNG") plotFactorRectangles.py factors1000.txt rectPlot.png
Nice. This plots all the factors up to and including 1000. The bottom row shows the primes, the second row shows all the factors of the even numbers, the third all the factors paired with three etc. I guess the question is why don't the primes fit and get squeezed out? It just occured to me that if I want to generate all the factors for integers below a certain value then I just need to follow that pattern. To generate the ten million I did previously should only take minutes, not hours! I'll have to have a fiddle with that... So, now, why stop at two dimensions? What if we play with three dimensions? What do three dimensional factors look like? I guess the first three dimensional factorizable integer would be 2×2×2 = 8. Which would mean 1,2,3,4,5,6,7 are primes in this 3D world, equivalent to 1,2,3 in two dimensions maybe? Those sequences are both less than 2n where n is the number of dimensions. So 1,2,...,14,15 would follow as prime in four dimension etc. The next factorizable integer in 3D is obviously 2×2×3 = 12, then 2×2×4=16. Lets have a look at some cuboids:
I just generated some cuboid factors with this perl script: genCuboidFactors.pl
my $x,$y,$z=0; my @arrFactors=(); my %hshUnique; my $intMaxDimension=0; $intMaxDimension=($ARGV[0]/4); for($x=2;$x<=$intMaxDimension;$x++) { for($y=2;$y<=$intMaxDimension;$y++) { for($z=2;$z<=$intMaxDimension;$z++) { my @a=($x,$y,$z); @a=sort(@a); #print("@a ".$x*$y*$z."\n"); if(!$hshUnique{"@a"}) { $hshUnique{"@a"}=1; $arrFactors[$x*$y*$z].=" @a"; } } } } for($c=1;$c<$intMaxDimension*4+1;$c++) { print("$arrFactors[$c]\n"); } After looking at the results it basically looked like normal 2D numbers except spread out more. E.g.:
Which, I guess, makes sense as each face of our cuboid has to have a factorizable area so the third dimension would only be multiplying out this value. Each factorizable integer is merely multiplied by the third dimension, for example 4 (2×2) gets multiplied by 2 to become 8 (2×2×2) which then gets repeated by 3, 4 becomes 12 (2×2×3). |