Skip to main content
Known Participant
May 1, 2007
Question

Prime Calculator

  • May 1, 2007
  • 47 replies
  • 4835 views
Hello everyone,

for the last week i have been trying to develop a prime number calculator. at first, it was a single input function that determined if it was prime or not. now it takes two numbers (min, max) but it takes to long and is not efficient enough to computer anything large within a certain range. (i.e. 0-15000). how would i make this algorithm significantly more efficient... without using the for loop to compare each number against a modulus check.

////////////////////////////////////////////////////////////////////
code attached with screen print of flash file
////////////////////////////////////////////////////////////////////
download zip version with all files:
rar version: prime number test (flash cs3+as2)
zip version: prime number test (flash cs3+as2)
thank you for any help
isaaac
This topic has been closed for replies.

47 replies

kglad
Community Expert
Community Expert
May 14, 2007
what elements are in part3?
Known Participant
May 14, 2007
well... am i not kglad i did that... WELL kglad here is my conclusion:

after testing the individual movie clips for any error producing syntax and then eliminating a single entity within the movie clip at a time for eventually all the main movie clips i was unable to located the producer of the error. the tab key initiates the display of the error and for no other reason does it come up until you press the tab button. after looking further into that i found that part3 and part4 (however if i take out part3, part4 works fine) movie clips were the only ones that show that. prior to entering those two sections there was no error produced by tabbing... curiously i developed an extra section called part5 which consists of two text inputs and tested them... the error was displayed however there was something different. in the previous two movies the error would pop up in the output box and then the tab would go to the default (well in this case the instance that was set to tab index 1). in the part5 section i did not set tabs initially and the results were the tab order was set automatically based on which ones i added to the stage and in the order i added them... after noticing that i assigned tab orders (x1.tabindex=1 and x2.tabindex=2) and tested it. the same errors popped up however the tab on them was messed up. instead of tabbing to the next text input box like it did before, it would continue to tab itself back to the first x1 text input box and never move or go to the following box. i have no idea how to fix this and i am lost. this really stinks.
kglad
Community Expert
Community Expert
May 13, 2007
good luck!
Known Participant
May 13, 2007
haha, yeah i guess your right, i can use auto incrementing column that has an id 1 - field and recalls information from the unique iq.

2 - hmmm, you know, i have done a million tests to fix the 2025 error but none of them have been to remove a single instance at a time... i will do that today and let you know what happens, thank you for the tip, ill post the results in a few. god i hope that works.
kglad
Community Expert
Community Expert
May 13, 2007
1. you don't need to encrypt anything for that unless you're afraid some third party is going to be sniffing the data transmitted from flash (and your user) to your database (and you) or from your database to flash or you're afraid to store unencrypted data on your server.

if i create a login of kglad and a password of kglad, then your database should store that info along with pointers to the other data i am entitled to see.

when i login to your database would recognize me and the pointers would allow me to access the data that you make available.

no encryption is needed unless you're concerned about data being intercepted when going from the user (flash) to the you (database) or vice-versa or you're concerned about storing unencrypted data on your server.

2. so, there's one movieclip containing several components that's on-stage when the problem occurs? if so, remove the components one-by-one until you pinpoint the problem.
Known Participant
May 13, 2007
1 - ummm well what i was trying to do was create a full flash site that calls/recalls/updates/adds information from a mysql database and relies on php to do that. for example the login section... i do not want someone retaining access to any part of an account that is not their's... i mean that makes sense. all i am trying to do is prevent that from happening. the user has to connect to the database to verify their input username and password are correct so how can i securely do that.

2 - yeah, from the error i received i denoted the problem was within the non-child object... the thing is i do not know how to fix that. the objects are setup as follows...
flash file > scene > frame 1-10 (start) / frame 11-20 (register) > movieclip
from within each part of the movie (start, register, ...) is a single movieclip that has all the parts which consist of all flash cs3 components and the event actions call functions derived from a class that links to all the other classes.

the files can be downloaded here: http://network.isaacewing.com/rar/network.rar
Known Participant
May 13, 2007
yes to both, i do not want any sort of security risk during the send/receive process... or at least minimize them as much as possible.

the second part is yes, i have specified tabbing orders for each part of the document. in order to provide a more organized and structured way to input (not that it is necessary however i think it is nice to have setup in the background) i set the unique tab order for each part of the document in in order to provide a sort of ease for the users that tab to the next input part or section rather than use their mouse. there are roughly eight sections right now and the first two work fine, the last one works all work in their own realm however when i combined them the problem arises. as noted in the topic argument error 2025 i have denoted through trial and error that the problem resides with the part2 and/or part3 sections and after testing for some time yesterday and today i have come to the conclusion it has nothing to do with the tab keys... the error is returned when you tab but the actual error probably has something to do with the name of a variable that overlaps another one (i.e. matching variable names). although i have not successfully tested this and found this to be true it is my current hypothesis for why this error is occurring.
kglad
Community Expert
Community Expert
May 13, 2007
1. you can't use flash and an adaptation of rsa to securely encrypt data. the prime building blocks will be too small. their product can be easily and quickly factored (see the link i posted, for example).

is that what you had in mind? something similar to rsa where you create a (public) key (the product of two large prime numbers) to encrypt your data and then you use the two primes to decrypt the data?

2. from that error message it looks like flash is trying to pass a mouse event handler to a non-child display object. are you trying to get some object to respond when you tab into another object?
kglad
Community Expert
Community Expert
May 13, 2007
are you concerned that information will be intercepted after it's sent from flash and before it's received by your php script?

error 2025: have you explicitly defined tab ordering for objects in that area of your document?
Known Participant
May 13, 2007
i am trying to test numbers for primality because i want securely transfer information and variables from flash to php scripts for sending/receiving through a site i am developing right now. do i need to use that kind of security when calling php scripts or does it not matter. i have one other problem (well it is the real problem, everything else is just semantics like the prime calculator, i really would like to figure that out but i just do not have the knowledge/knowhow) and that problem is the displayobject function flash cs3 and as3 report when i press the tab key in a certain area of my document... the forum is argument error 2025...
Known Participant
May 13, 2007
actually i read your previous posts thoroughly and i loved them. they were very informative... my question is with the attached code... that is what ran for 4:50, was it those two input values which are 1,000,021 to 1,000,041... so it took that long to computer them... one of my friends said the way to calculate efficiency is to use the formula O(n), where n is b - a... does that make sense. so using that formula and determining its solution would using c or c++ or java be a better way to compute this algorithm or is it irrelevant.
kglad
Community Expert
Community Expert
May 13, 2007
the above code executes in less than 600ms on my computer.

the comment about extending the default actionscript timout was directed to rothrock who asked if anyone could extend the timeout beyond 60 seconds.

when you talk about efficiency or speed in this forum there are 2 main things to consider:

1. the efficiency of actionscript
2. the efficiency of the algorithm encoded by your actionscript.

the main problem here, is 1: actionscript was not designed to handle arithmetic calculations efficiently and is not designed to handle large numbers nor a high degree of accuracy in its calculations.

it makes no difference whether you use rabin-miller (that i encoded above and is, for numbers that flash can handle, 100% reliable and is big oh of 7*log-cubed of n or you found an algorithm that's 100 times more efficient that rabin-miller.

actionscript would still be too slow and is still limited in the magnitude (32-bit) of numbers it can handle.

so, to do any signficant calculations involving prime numbers you would want to use a language more adept at handling arithmetic calculations. for example, check the calculation speed at the below link. try 50!+1 and look how fast that number is factored. and then look at the length of that source code.

actionscript would require nearly an eternity to execute that code and still couldn't handle numbers that large and so would yield an erroneous result.

http://www.alpertron.com.ar/ECM.HTM

but again, what are you trying to do? why are you trying to test numbers for primality?