Jump to content
Sign in to follow this  
ShadowMage

Challenge: Sieve of Eratosthenes, in PHP

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? :)

Share this post


Link to post
Share on other sites

The next challenge is to create Facebook in as few lines of code as possible. Entries are due Wednesday.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

A lot of my sieve-time came when I needed to get away from my spousal unit. Sadly, this is often. :) And no, your task sounds like a regex from hell.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...