![]() |
Primes in a spreadsheet
When searching around for a [I]soft copy[/I] of primes on the internet, pickings are surprisingly scarce. You come across text lists with no particular alignment specifications and comma separated lists with other info embedded, so there's a bunch a data cleansing that needs to be done.
Does anyone have an Excel spreadsheet with just one column with a bunch of primes, one in each row? |
See Here:
[url]http://www.mersenneforum.org/showthread.php?t=15705[/url] Since you aren't (yet) interested in particularly large primes, the very basic 10-line program being discussed there should work fine for you, and you can ask it for any alignment you like. Just import the result into your spreadsheet. And be careful not to overwhelm the spreadsheet; there are 60,000 or so primes under 10^6. |
Here's some more basic code for Pari/gp:[code]\\default(primelimit,10^7); \\ The default is only 500,000. Maximum value is 4,294,965,247. Uncomment the start of the line and set appropriately as needed.
output_file="C:/primes.csv"; \\ Where do you want your primes? start_prime=2; \\ Does not need to be prime, it will start from the first prime after this value. end_prime=10^3; \\ Also does not need to be prime, it will stop at the last prime before this value. { forprime(p=start_prime,end_prime, write(output_file,p); ); }[/code]Just copy that into a text file then you can run it by typing something like this in Pari:[code]\r drive:/path/to/file.txt[/code] By default it will output primes from 2 to 1000 as a CSV file on your C: which can be directly opened by Excel. Note that if the file already exists, it will add to it, not overwrite it. You can download Pari/gp [url=http://pari.math.u-bordeaux.fr/download.html]from here[/url]. |
There are some prime generators around. Some are allow you to pick a starting point and the number to generate. FWIW, it will be faster to generate them than to have excel save them.
here is one simple one: [url]http://javaboutique.internet.com/prime_numb/[/url] |
I'll add another vote for PARI/GP (make sure to download the "Windows binary" if you're running Windows). Here's how I'd code it:
[code]makePrimes(howMany, file)={ if(default(primelimit) < howMany, default(primelimit, howMany)); forprime(p=2,howMany,write(file, p)) }; makePrimes(100000, "c:/location.csv")[/code] |
[QUOTE=CRGreathouse;265122]I'll add another vote for PARI/GP (make sure to download the "Windows binary" if you're running Windows). Here's how I'd code it:
[code]makePrimes(howMany, file)={ if(default(primelimit) < howMany, default(primelimit, howMany)); forprime(p=2,howMany,write(file, p)) }; makePrimes(100000, "c:/location.csv")[/code][/QUOTE] thank's for the code is there a way to list them across the top as well to create a multiplication chart ? |
[QUOTE=science_man_88;265134]thank's for the code is there a way to list them across the top as well to create a multiplication chart ?[/QUOTE]The write() function includes a line break at the end, the write1() function does not.
|
[QUOTE=lavalamp;265157]The write() function includes a line break at the end, the write1() function does not.[/QUOTE]
tried it and nothing appeared in the complete spreadsheet. |
[QUOTE=science_man_88;265188]tried it and nothing appeared in the complete spreadsheet.[/QUOTE]Might it be that one needs to do at least one write() after all the write1()s are issued?
|
[QUOTE=cheesehead;265195]Might it be that one needs to do at least one write() after all the write1()s are issued?[/QUOTE]
It might! Trying that now. Thanks for the suggestion. |
[QUOTE=science_man_88;265199]It might! Trying that now. Thanks for the suggestion.[/QUOTE]
doesn't work at last check. took out one thing first to try. I still haven't found a way that seems to work. |
| All times are UTC. The time now is 22:55. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.