Hacking Thy Fearful Symmetry

Hacker, hacker coding bright

NoCOUG SQL Challenge – thinking outside the padded box

February 19, 2011
perl sql nocoug golf

Seems that our André Araujo has already spilled the beans and revealed his solution to the second edition of the NoCOUG SQL Challenge.

Now, I can’t let him have all the fun, can I?

Unfortunately, my SQL-fu is pathetically weak, so I stand no chance against his Querying Might. Buuut I am well versed in another art. A darker art. A terrifying art: Perl golf.

You might want to get the children out of the room before you continue reading. Pregnant women and the elderly might also want to avert their eyes. It ain’t going to be pretty.

... everybody with a weak stomach has left the premise? Good.

To be able to work with it, I’ve exported the riddle table into a space-delimited file, looking like this:


With the data in that format, I can now solve the riddle with:

#!/usr/bin/perl -p
s/ (\w+)/lc$&/e;$k{$1}=$_}{/ /&&s/[A-Z]+/$k{$&}/,$x[y---c]=$_

While this script prints the secret message, it’s not very well formatted. If we want to be prettier, we can always do:

$ ./nocoug.pl data | perl -0lpe's/\s+/ /g'

For the time being, I’ll resist the urge to deconstruct and explain my solution. Instead, I’m going to add a meta-level to the challenge. Can you figure out how I’m solving the unspoken problem? And if you do, can you translate it into an Es-Cue-El invocation? While keeping some grasp on your sanity?

comments powered by Disqus

About the author

Yanick Champoux
Perl necrohacker , ACP writer, orchid lover. Slightly bonker all around. he/him/his