BlogKontaktTagcloud

Coding Contest

Unfortunatly I can not resist if somebody brings up a coding contest. This time Travis and Paul wrote about the coding contest of php architect at planet-php. I did not invest a lot time into it, but still ways more then I planed.

The problem is that the ranking is once by speed and once by size of the script. Two parameters which usually not go well together. After having some great ideas for speeding up my code (even parallel processing, shared memory and map-reduce came to my mind) I decide to let this race to others and fully concentrate to the size. I not even run benchmarks anymore.

Unfortunatly some nasty html special cases (whitespace, case independence, single- and double-quoting, various attributes and so on) blow my perfect sized script a bit. But with some nasty php method tricks it's hopfully still the shortest possible script that gets all valid cases.

Just to let you feel not to save, I wrote a littel nasty html example that might break your own script. (You should get exactly 10 11 links out of it.)
Ähnliche Beiträge:
Jira status
Mailstatus in Skype
PHP Quine
What's php like?
Zend Framwork 1.5 is out
Comments (11)  Permalink

comments

Mirko Stocker @ 25.02.2008 22:20 CET
Hm, mein Ruby-script gibt bei deinem Beispiel folgendes aus (11 Links):

http://en.wikipedia.org/wiki/Hyperlink
/w/index.php?title=Hyperlink&action=edit&section=3
/wiki/Inline_linking
/wiki/Thumbnail
#Image_resolution
/wiki/Preview
/wiki/Cropping_%28image%29
/wiki/Magnification#anchor
/wiki/Desktop_publishing
/wiki/Page_layout
http://validator.w3.org/check?uri=referer

und sieht so aus:
s.scan(/]+fs*=s*(["'])([^"']+)1/i) {|_, l| puts l}
(s ist ein String mit dem HTML drin)
Mirko Stocker @ 25.02.2008 22:21 CET
Uh, der Regex hat leider nicht ganz überlebt.. sorry :)
Paul Reinheimer @ 25.02.2008 22:23 CET
I'm lazy, can I just use your same HTML page for the example on the site?
leo @ 25.02.2008 23:16 CET
@mirko: Go away with the regex, that's the secret sauce! And I was sure ruby will be shorter (was allready on the way to ask you). And yes they're 11 links. I'm a n00b not able to use wc correct.

@Paul: Sure! Feel free to take it for the final test as well ;-)
Bob @ 26.02.2008 00:18 CET
Hi, nice example!

One thing that you might want to add ot it, is a commented out link, which should not be counted. Like this:

<-- This is a commented out link -->
Bob @ 26.02.2008 00:19 CET
Crap, it ate my code. Let's try again:

<-- This is a commented out link <a href='example.org' /> -->
Paul Reinheimer @ 26.02.2008 03:54 CET
Why isn't there 11 links? I get 11 opportunities to click? (including the valid button)

http://en.wikipedia.org/wiki/Hyperlink
/w/index.php?title=Hyperlink&action=edit&section=3
/wiki/Inline_linking
/wiki/Thumbnail
#Image_resolution
/wiki/Preview
/wiki/Cropping_%28image%29
/wiki/Magnification#anchor
/wiki/Desktop_publishing
/wiki/Page_layout
http://validator.w3.org/check?uri=referer
leo @ 26.02.2008 08:42 CET
@Paul: Yes, Mirko already mentioned. I'd counted wrong.
@Bob: That's a nasty one. Didn't thought about this one so far. I will tune my script and (probably) add another test script.
@leo's @ 27.02.2008 21:15 CETTRACKBACK
As I allready mentioned I can't let my finger from coding contest. Unfortunately Bob found in a comment in my blog more nasty stuff about links in html comments which makes parsing even harder. I tr ...
Silvan | tilllate.com @ 01.03.2008 19:01 CET
What have you done, Leo? You told me about this contest and I now forgot about wife and kid while twitching on the bytes :-)
leo @ 04.03.2008 03:57 CET
I don't worry about YOUR kid and wife. Hopefully your wife or Orell stopped you before you get only close to my solution.

add a comment

The Trackback URL to this comment is:
http://leo.freeflux.net/blog/plugin=trackback(2580).xml

This blog is gravatar enabled.
Your email adress will never be published.
Comment spam will be deleted!

Name*
E-Mail
For Spammers Only
URL
Kommentar*
E-Mail Benachrichtigung bei neuen Kommentaren zu diesem Eintrag
Speichere meine Daten (braucht Cookies)