Sign in to follow this  
Followers 0
Dethredic

Prime Numbers

16 posts in this topic

Well i have a math project n Prime Numbers and i was thinking ok making a program to calculate prime numbers.

(who ever heard of a math project)

http://www.autoitscript.com/forum/index.ph...=24643&st=0

the above forum and some other help i came up with the prime finder.

you enter a number and it tells you if it is prime.

I would like to make it list the factors (if possible) maby due to some large numbers it would have to be only up to 25 or so factors.

another possible program i would like to make would go through the numbers 1-10000 (maby more but doubt it) and list all the prime numbers it came across.

I dont know how to start my second idea. HELP PLZ!!! I might be able to use the same function but im not sure.

(if there is already a forum which could help me it would be appreated.)

also if you see a flaw or a way to make the "Prime Finder" better plz tell me

thanks


"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You seriously have to use the SEARCH FORM before you post. Or take a Quick look in Scripts and Scraps. You'll find a whole TOPIC with several ways on how to calculate primes etc.

With that out of the way, here's my function that uses the sieve of Eratosthenes. It checks for $n number of numbers if it is a prime or not, and returns that as a array. Use _ArrayDisplay on the return value and you will definately know what I mean. :)

Func Eratosthenes($n)
    Dim $a[$n+1]
    For $i = 0 to 1
        $a[$i] = 0
    Next
    For $i = 2 to $n
        $a[$i] = 1
    Next
    Dim $p = 2
    While $p^2 < $n+1
        $j = $p^2
        While $j < $n+1
            $a[$j] = 0
            $j = $j + $p
        WEnd
        Do
            $p += 1
        Until $a[$p] = 1
    WEnd
    Return $a
EndFunc

Edit: It said 'EndFun' at the end of my script. But the fun's only just starting, so I changed it to EndFunc.

Edited by Manadar

Share this post


Link to post
Share on other sites

Hi Manadar-

I have to write a PhD thesis on the efficacy of Flintstone vitamins on the aleviation of agita in males over 60. Can you help me or should I also use the search function? I wish forums existed when I was in high school!


...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I seriously hope you are joking :)

I'm not an encyclopedia, I have no idea what you are talking about.

Edit: After going over your post a few times, I still don't understand it.. Mathematics is my thing, biology isn't.

Edited by Manadar

Share this post


Link to post
Share on other sites

Mandar

i did search the forums and i found you post like that under the link i specified above.

i downlaoded it and saved it and it ran and it jut kept putting a zero and 1 beside the numbers that scrolled really fast. (i waited till about 50000 then quit)

i need a way to record the numbers that are prime and possibly wat there factors are.

i was trying to see if there was any otherways this could be done(not just your way)

i was also looking for advice on my first script.


"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

You are checking that IsPrime() function for @error, but it does not support it. This one here does which allows you to leave out @error checking but still have a boolean (True/False) effect.

:)

Edited by MHz

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Mandar

i did search the forums and i found you post like that under the link i specified above.

i downlaoded it and saved it and it ran and it jut kept putting a zero and 1 beside the numbers that scrolled really fast. (i waited till about 50000 then quit)

i need a way to record the numbers that are prime and possibly wat there factors are.

i was trying to see if there was any otherways this could be done(not just your way)

i was also looking for advice on my first script.

If $a[$n] = 1 Then

;$n is a prime number

EndIf

List it. It's a school project, You have to do something..

Edited by Manadar

Share this post


Link to post
Share on other sites

ok

watever

wondering if i could do something like this in autoit

http://javaboutique.internet.com/prime_numb/

that would be perfect but ill need some help


"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

If the help I am giving you is worth a 'watever' while it's very good and structured! Go play in traffic! Seriously. Do it yourself.

Edit: Replaced 'Go kill yourself'.

Edited by Manadar

Share this post


Link to post
Share on other sites

lol

manadar calm down

i just had something different in mind

can u live with that??


"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

Share this post


Link to post
Share on other sites

im being resourseful

give me that


"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

Share this post


Link to post
Share on other sites

im being resourseful

give me that

First of all, if your making a program to do your homework that sounds just a tad like cheating. And second, cheating through being "resourseful" is the same as cheating.


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

well not soon

the teacher hasent come up with the guidelines for the project.

we can prettymuch do watever(im doing a website)

so not for at least a couple weeks


"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

Share this post


Link to post
Share on other sites

well not soon

the teacher hasent come up with the guidelines for the project.

we can prettymuch do watever(im doing a website)

so not for at least a couple weeks

Dethredic,

I don't think that making a program is like cheating, as Piano_Man suggested. But I do think that it's important for you to know the concepts of prime numbers and how and why your program finds them in the most efficient way possible.

When you first started this thread, I wrote an AutoIt script that finds the first 10,000 prime numbers and writes them to a text file in less than one minute. It only took a little searching in this forum to get started and a little more searching on the internet to make it much faster.

I wouldn't be doing you a favor by posting this script right now. And you would be doing yourself an injustice by just copying someone elses code, especially if you couldn't follow what it was doing or why.

If you want to get a good grade for this project, and learn something in the process, this is what I suggest you do:

First, document everything that you do so you can turn it in with your project. This will help show your teacher that you thought things through and learned during its development. That alone is worth a grade. Teachers want to see how you came to get your answer; not just the answer. This is why students get partial credit, even if their answer is wrong.

Second, state your objective and list everything you want your program to do.

Third, break it down into small pieces and complete each task. This will help in troubleshooting.

And last, put it all together.

I am sure that I have overlooked some things and you will find that many people in this forum will be more than happy to help you, if you show that you are trying to help yourself. So, when you get to the third step listed above, post some of your code and explain what that part is trying to do.

Hopefully, someone will help you by giving you more ideas that point you in the right direction, and not just showoff by writing it for you.

A math project may seem silly to you. But you have a chance to develop how to do a project correctly now, that will help you get better grades easier in collage and understand things more quickly when you land that good job.

I am one of the people who will help you, if you help yourself.

taurus905


"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0