Click here to Skip to main content
15,064,140 members
Home / Discussions / C#
   

C#

 
AnswerRe: Sieve of Eratosthenes Pin
Pete O'Hanlon12-Sep-12 4:54
mvePete O'Hanlon12-Sep-12 4:54 
GeneralRe: Sieve of Eratosthenes Pin
WebMaster12-Sep-12 4:59
MemberWebMaster12-Sep-12 4:59 
GeneralRe: Sieve of Eratosthenes Pin
J4amieC12-Sep-12 5:02
MemberJ4amieC12-Sep-12 5:02 
GeneralRe: Sieve of Eratosthenes Pin
Manfred Rudolf Bihy12-Sep-12 5:06
professionalManfred Rudolf Bihy12-Sep-12 5:06 
GeneralRe: Sieve of Eratosthenes Pin
J4amieC12-Sep-12 5:07
MemberJ4amieC12-Sep-12 5:07 
GeneralRe: Sieve of Eratosthenes Pin
Pete O'Hanlon12-Sep-12 5:04
mvePete O'Hanlon12-Sep-12 5:04 
GeneralRe: Sieve of Eratosthenes Pin
WebMaster12-Sep-12 5:16
MemberWebMaster12-Sep-12 5:16 
GeneralRe: Sieve of Eratosthenes Pin
Pete O'Hanlon12-Sep-12 5:22
mvePete O'Hanlon12-Sep-12 5:22 
I understood your code perfectly. I can't help it if I'm able to understand algorithms better than you can; it's called age, wisdom and experience.

What I needed you to do is actually go and read the algorithm itself. The sieve is not brute force - your code is. I'm guessing that this is a homework assignment for you, so I'm not going to give you the code - but the pseudocode in the wikipedia article articulates the solution perfectly. Perhaps if you actually tried that algorithm rather then you'd see why I'm saying what it is.

Meysam Tolouee wrote:
for (int p = 0; p < numbers.Count - 1; p++)

You don't need to go all the way through to the end of the list. You only need to go to the square root of n.

Meysam Tolouee wrote:
if (numbers[j].Value % numbers[p].Value == 0)

Not needed. The sieve doesn't require this test.

*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

"Mind bleach! Send me mind bleach!" - Nagy Vilmos


CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

GeneralRe: Sieve of Eratosthenes Pin
J4amieC12-Sep-12 5:23
MemberJ4amieC12-Sep-12 5:23 
GeneralRe: Sieve of Eratosthenes Pin
WebMaster12-Sep-12 5:48
MemberWebMaster12-Sep-12 5:48 
GeneralRe: Sieve of Eratosthenes Pin
J4amieC12-Sep-12 5:59
MemberJ4amieC12-Sep-12 5:59 
GeneralRe: Sieve of Eratosthenes Pin
WebMaster12-Sep-12 6:11
MemberWebMaster12-Sep-12 6:11 
GeneralRe: Sieve of Eratosthenes Pin
Rage12-Sep-12 6:23
professionalRage12-Sep-12 6:23 
GeneralRe: Sieve of Eratosthenes Pin
Pete O'Hanlon12-Sep-12 6:25
mvePete O'Hanlon12-Sep-12 6:25 
AnswerProper implementation of Sieve of Eratosthenes Pin
Clifford Nelson12-Sep-12 10:45
MemberClifford Nelson12-Sep-12 10:45 
GeneralRe: Proper implementation of Sieve of Eratosthenes Pin
WebMaster12-Sep-12 11:00
MemberWebMaster12-Sep-12 11:00 
AnswerRe: Proper implementation of Sieve of Eratosthenes Pin
Clifford Nelson12-Sep-12 11:20
MemberClifford Nelson12-Sep-12 11:20 
GeneralRe: Proper implementation of Sieve of Eratosthenes Pin
Dave Kreskowiak12-Sep-12 12:44
mveDave Kreskowiak12-Sep-12 12:44 
GeneralRe: Proper implementation of Sieve of Eratosthenes Pin
Clifford Nelson12-Sep-12 13:07
MemberClifford Nelson12-Sep-12 13:07 
GeneralRe: Proper implementation of Sieve of Eratosthenes Pin
Dave Kreskowiak12-Sep-12 18:25
mveDave Kreskowiak12-Sep-12 18:25 
AnswerRe: Sieve of Eratosthenes Pin
Thomas Daniels12-Sep-12 5:29
mvaThomas Daniels12-Sep-12 5:29 
AnswerRe: Sieve of Eratosthenes Pin
Kenneth Haugland13-Sep-12 3:33
professionalKenneth Haugland13-Sep-12 3:33 
AnswerRe: Sieve of Eratosthenes Pin
PIEBALDconsult12-Sep-12 14:23
professionalPIEBALDconsult12-Sep-12 14:23 
QuestionSubstitution of Paths in HyperLinkField with File Names Pin
ASPnoob12-Sep-12 4:23
MemberASPnoob12-Sep-12 4:23 
AnswerRe: Substitution of Paths in HyperLinkField with File Names Pin
Pete O'Hanlon12-Sep-12 4:55
mvePete O'Hanlon12-Sep-12 4:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.