Jump to content

Challenge: Sieve of Eratosthenes, in PHP


ShadowMage

Recommended Posts

The challenge of array splice is that every element after the deleted element gets reindexed. So if you're using a counter as an index, elements are no longer where you think they are. That's why my original technique looped through the array backwards. Your original technique avoided the problem by breaking out of the loop every time array_splice was called.In your new experiment, I think you're also breaking the array_walk rules. You are changing the structure of the array, and this will lead to unpredictable results. So says the manual. I suspect it just iterates like 0, 1, 2, 3 and doesn't make the allowances that array_filter does.
Hmm....Yes, indeed, the manual does say that doesn't it....I really hope we can keep this 'contest' going. This is kinda fun. And very educational. Who's got next week's challenge? :)
Link to comment
Share on other sites

  • Replies 55
  • Created
  • Last Reply

I wondered when jsg was going to show up in this thread. Somehow I've been imagining you laughing at the whole thing.I would totally recode Facebook if I gave a rat's ass about it and all its mediocre ilk. May they perish from the earth.

Link to comment
Share on other sites

I was going to post a thinly-disguised attempt to get everyone to do my work for me. How about an algorithm to "most reliably" strip replied-to text out of an email, sent from as many different clients as possible? Sounds fun, right? Yeah, I would have liked to have developed a nice little sieve, but this is a busy week for me with work. Between working, eating, and Sid Meier, my free time is at a premium right now.

Link to comment
Share on other sites

Although I came across this thread too late to participate, I think the idea of having contests like this is a good one. As long as they stay good-natured and educational. I learned something just by reading this thread: that is, the range() function. Just like ShadowMage said, it could save many lines of code.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...