Page 2 of 2 FirstFirst 12
Results 41 to 52 of 52

Thread: [RESOLVED] Prime number code

  1. #41
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Prime number code

    Quote Originally Posted by incidentals View Post
    Kaliman makes and observation that i had missed

    he is correctly states that the test does not need to go right upto the value being tested

    but instead only half way
    Nice catch Khali...

    Me too missed that one.

    @shardooni: Glad to hear that you got the solution. It would be a good thing if you have marked this thread as RESOLVED. You could use the "Thread Tools" found at the top of this page and choose "Mark as RESOLVED" or you could edit the very first post and add "[RESOLVED]" in the beginning of the title. The reason is that, when others view your thread, they could easily understand that you have got it solved.


    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  2. #42
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Prime number code

    here's my solution:

    vb Code:
    1. Dim uBound As Integer = 999
    2. Dim primes() As Integer = Enumerable.Range(2, uBound - 1).Where(Function(i1) i1 = 2 OrElse Not Enumerable.Range(2, i1 - 3).Any(Function(i2) i1 Mod i2 = 0)).ToArray
    3. ListBox1.Items.AddRange(Array.ConvertAll(primes, Function(x) x.ToString))

  3. #43
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: Prime number code

    best thing to do then is

    set out you requirements

    and make a little plan of action and then we can help you build it from the
    start

    outline plan and fill in bit by bit

    here to talk

  4. #44
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Prime number code

    here's an improved Prime number finder:

    http://www.vbforums.com/showthread.p...45#post4108845

  5. #45

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    35

    Re: Prime number code

    Quote Originally Posted by incidentals View Post
    best thing to do then is

    set out you requirements

    and make a little plan of action and then we can help you build it from the
    start

    outline plan and fill in bit by bit

    here to talk
    soundss great. should I post the new part for this assignment in another thread or can I just talk to you guys through this one? The next part of the assignment involves embedding another loop of primes into the loop the first "prime number" loop.

  6. #46

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    35

    Re: [RESOLVED] Prime number code

    okay so the flow chart for the next part is called " simple prime sifter". i have to add this part INSIDE the loop of the first prime number loop you guys helped me on. I am going to attach a picture of the loop to this message. I am going to start working on it meanwhile, but hopefully you guys can help me out with how to start off. flow chart
    Last edited by shardooni; Dec 23rd, 2011 at 10:55 AM.

  7. #47

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    35

    Re: [RESOLVED] Prime number code


  8. #48

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    35

    Re: [RESOLVED] Prime number code

    heres the pic. sorry i dont know why those others pic i posted arent working
    flow chart

  9. #49

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    35

    Re: [RESOLVED] Prime number code

    i have a feeling that flow chart is the code we just did yesterday !! is it?

  10. #50
    Hyperactive Member Lenggries's Avatar
    Join Date
    Sep 2009
    Posts
    353

    Re: Prime number code

    Quote Originally Posted by incidentals View Post
    Kaliman makes and observation that i had missed

    he is correctly states that the test does not need to go right upto the value being tested

    but instead only half way

    so function isprime can work much faster ( potentially twice as fast ) if we change the limits of the test loop

    and the divisible by 2 doenot need to be tested as the candidates are all odd
    I realize I'm late to the party, but in case this thread ever gets read by anyone else, I wanted to point out a couple items.

    First, the method described for primality testing in this thread is a variant of what is called the Sieve of Eratosthenes. This technique is fine for determining if small numbers are prime, but is horrible for large numbers (by which I mean the kinds of prime numbers used in modern encryption algorithms). For those kinds of numbers you should use other methods.

    That said, when using the Sieve, you only need to count up to the square root of the number being tested, not half the number, which can make a significant difference. Thus, line 25 in akhileshbc's last example of code should be:
    Code:
    For j As Integer = 3 To Math.Floor(Math.Sqrt(i))

  11. #51
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: [RESOLVED] Prime number code

    Thanks for sharing it with us Lenggries

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  12. #52
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Prime number code

    Quote Originally Posted by incidentals View Post
    glad she has got it

    didn't we do well

    the problem with my code is its for vb6 not net

    so
    listbox.additem x
    is now
    listbox.items.add x

    oh well

    btw kaliman the mod operator is the modulus (the remainder due to whole number division) not the module

    I have this need to teach... sorry

    now if she would just remember to rate out posts

    here to talk
    Thank you, its kind of embarassing, but keep in mind English is not my native language, in Spanish is "Modulo", which translates both to "Modulus" and "Module".
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width