|
-
Dec 22nd, 2011, 10:13 PM
#41
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,...
-
Dec 23rd, 2011, 05:06 AM
#42
Re: Prime number code
here's my solution:
vb Code:
Dim uBound As Integer = 999
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
ListBox1.Items.AddRange(Array.ConvertAll(primes, Function(x) x.ToString))
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 23rd, 2011, 05:07 AM
#43
Frenzied Member
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
-
Dec 23rd, 2011, 08:09 AM
#44
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 23rd, 2011, 10:17 AM
#45
Thread Starter
Member
Re: Prime number code
 Originally Posted by incidentals
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.
-
Dec 23rd, 2011, 10:52 AM
#46
Thread Starter
Member
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.
-
Dec 23rd, 2011, 10:53 AM
#47
Thread Starter
Member
Re: [RESOLVED] Prime number code
-
Dec 23rd, 2011, 10:54 AM
#48
Thread Starter
Member
Re: [RESOLVED] Prime number code
heres the pic. sorry i dont know why those others pic i posted arent working
flow chart
-
Dec 23rd, 2011, 11:04 AM
#49
Thread Starter
Member
Re: [RESOLVED] Prime number code
i have a feeling that flow chart is the code we just did yesterday !! is it?
-
Dec 23rd, 2011, 04:35 PM
#50
Re: Prime number code
 Originally Posted by incidentals
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))
-
Dec 24th, 2011, 01:46 AM
#51
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,...
-
Dec 26th, 2011, 04:27 PM
#52
Re: Prime number code
 Originally Posted by incidentals
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|