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 exactly10 11 links out of it.)
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
comments
I'm lazy, can I just use your same HTML page for the example on the site?
@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 ;-)
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 -->
Crap, it ate my code. Let's try again:
<-- This is a commented out link <a href='example.org' /> -->
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§ion=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
@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 22:15 CESTTRACKBACK
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 ...
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 ...
What have you done, Leo? You told me about this contest and I now forgot about wife and kid while twitching on the bytes :-)
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!






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§ion=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)