Okay...
I have a function that determines whether or not a number is prime. Basically, you give it a number and it checks a big table of known primes and then it checks a few division tricks and then it checks to see if any of the numbers in the prime table divide it.
Of course, if it finds the number in the table, it immediately kicks back a TRUE.
The more tricky the number, the longer it takes to find. The final stages is that it just basically goes through brute force division to determine.
My table-of-primes is a table that contains the first 10,000 primes. However...
There are plenty of web pages and online resources that have long lists of primes.
Using only JavaScript, is there a way I can access some list out there. For example, my first thought was to find a list page and open it in a JS window and parse the code into an array.
But off the top of my head, I'm not sure if this is possible.
Suggestions? Ideas?
I have a function that determines whether or not a number is prime. Basically, you give it a number and it checks a big table of known primes and then it checks a few division tricks and then it checks to see if any of the numbers in the prime table divide it.
Of course, if it finds the number in the table, it immediately kicks back a TRUE.
The more tricky the number, the longer it takes to find. The final stages is that it just basically goes through brute force division to determine.
My table-of-primes is a table that contains the first 10,000 primes. However...
There are plenty of web pages and online resources that have long lists of primes.
Using only JavaScript, is there a way I can access some list out there. For example, my first thought was to find a list page and open it in a JS window and parse the code into an array.
But off the top of my head, I'm not sure if this is possible.
Suggestions? Ideas?
-
Re: Referencing an external resource...
Sun, February 26, 2006 - 10:03 AMMy question would be why would you want to do this on the fly? Why not create a new table yourslef during development with one of these resources so that the script already has it on hand? OR copy the page to the server in question and do it on the fly locally? -
-
Re: Referencing an external resource...
Sun, February 26, 2006 - 10:25 AMFair question.
There are a LOT of primes and new ones are being discovered all the time.
But, it would be acceptable to have a page or other separate resource on my server of just a big ass list of primes. A text file or even an HTML file would work.
Would that make it easier? -
-
Re: Referencing an external resource...
Sun, February 26, 2006 - 1:15 PMmost deinitely... you sould jsut open the file and create your prime table/array from it, then use it to check. Isnt ther elike a file.open() function? ive never used it but i swear i thought there was one. If not you could put the list in an xml doc as a single node, or if you wanna take the time make each prime a node, and then use xmlhttprequest to open it and get the data you want. -
-
Re: Referencing an external resource...
Mon, February 27, 2006 - 1:25 AMJavaScript has no official file capability. This is part of the trickiness. -
-
Re: Referencing an external resource...
Mon, February 27, 2006 - 3:49 AMid use xmlhttprequest then. -
-
Re: Referencing an external resource...
Mon, February 27, 2006 - 10:00 AMremember that xmlhttprequest doesn't specifically require an xml file to be returned. in this case, a full xml file would probably be too verbose. you may want to look into using JSON as the data format:
www.json.org/js.html
-
-
-
-
-