Jump to content

Recommended Posts

Posted

Hey guys!

 

It has been a while since I posted so hopefully this one will be good.

 

Basically I have a table of prime numbers. What is to write this table as an image - from 1 too 480000 - showing each cell that is a prime as white and the others as black.

 

So basically I'm cycling the numbers from 1-480000 and if they are prime then I want the cell white and otherwise black. I also want to be able to wrap the table to 800x600 pixels.

 

Any help appreciated.

Posted

The closest I've got so far is this:

 

Image[Table[if[PrimeQ[x], 1, 0], {x, 1, 800}, {y, 1, 800}]]

 

That makes an image but shows each line as either black or white instead of each cell.

 

I know I need to build a table and put it into the Image function but I can't figure out how to do it.

Posted
The closest I've got so far is this:

 

Image[Table[if[PrimeQ[x], 1, 0], {x, 1, 800}, {y, 1, 800}]]

 

That makes an image but shows each line as either black or white instead of each cell.

 

I know I need to build a table and put it into the Image function but I can't figure out how to do it.

 

That's because you're only testing the row number, not the cell. I'd do:

 

Image[Table[if[PrimeQ[x*800 + y], 1, 0], {x, 0, 799}, {y, 0, 799}]]

 

I think that gives the right result.

 

edit: err, wait, that might go vertically instead of horizontally. But you get the idea.

Posted (edited)

This is the formulation I ended up working with. It does what I need:

 

Size = 300
Image[Table[if[PrimeQ[y* (Size - 1) + x], 1, 0], {x, 1, Size}, {y, 1, Size}]]

 

Edit: That actually doesn't seem to work correctly. I may need to do some more work on it.

Edited by RyanJ
Posted

II eventually gave up on trying to perfect the formula in Mathematica so I wrote a program to generate the code for me. Here is the resulting image if anyone is interested:

 

http://bayimg.com/lAlKLaaCp

 

The highest prime used in this list is 104729.

Posted

I think that is just the rest of the number I chose to fold the lines. When I choose 10 cells per line it doesn't have the horizontal rows like that.

Posted

Ryan, I was thinking of the diagonal lines. Presumably, depending ton the grid size you choose, you could get a number of different patterns emerging.

 

Either way. I was quite pleased to see the result.

 

Nicely done.

Posted

Yeah. I understand what you are saying.

 

I can upload the C# project if anyone else wants to experiment with it. To see what other things we can do.

 

Though you would need Mathematica in order to process the codes.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.