Two Guys Arguing

King of the nerds – Quick and Dirty Programming Contest Winners

Posted in Uncategorized by benjaminplee on 01.24.10

Winning a vendor sponsored timed programming contest at a three day technical conference (CodeMash**) which you voluntarially traveled to in Northern Ohio in the middle of January is a double edged sword.

One the one side you are the king of the nerds.
On the other side …  you are the king of the nerds.

A few weeks ago Josh Schramm, Kevin Berridge, and I (all past Dayton Flyers and college roomates) took in a great CodeMash conference and decided to enter a StoutSystems sponsored programming SmackDown just for kicks.

We won.  All hail the kings of the nerds.

Granted only ~15 teams entered (from 1 -3 people each) but none the less, we won and only one other team submitted even a failed attempt before our winning one.

Josh posted our solution in Ruby to GitHub and I have since cleaned it up a bit, added the original rules, a C# & Linq solution Kevin did while we were there and a new one of my own making in Ruby.

I am planning to write the solution in a few different languages and designs.  If anyone else has an entry or can suggest a way to make the Ruby variant any cleaner or more idiomatic … please leave me a comment or fork my repo on GitHub.

Latest Ruby variation:

lines = []

File.open('../input.txt').each { |line| lines << line }

lines = lines[1..lines.size].
              map     { |line| line.split("\t") }.
              each    { |line| line[1] = line[1].gsub(/[^a-zA-Z]/, '').reverse }.
              reject  { |line| line[1].to_s.empty? }.
              sort    { |x, y| (x[1] <=> y[1]) == 0 ? (x[5].to_f <=> y[5].to_f) : (x[1] <=> y[1]) }.
              collect { |line| line.join("\t") }.
              insert(0, lines[0])

File.open("output.txt", 'w') { |f| f.write(lines) }

** CodeMash was an absolute blast.  Great sessions, good people, nice venue, and rockin’ live music.

Long live esenihc lavivrus

About these ads

3 Responses

Subscribe to comments with RSS.

  1. Josh Schramm said, on 01.24.10 at 6:08 pm

    Man i dont know if i love or hate that solution. On one hand its really concise. On the other hand its kinda hard to follow. Either way it reminds me of how badass ruby is.

  2. Kevin Berridge said, on 01.24.10 at 6:30 pm

    Functional Programming FTW! Wow.

  3. Gerald said, on 04.03.10 at 7:41 pm

    I like these, nice lines!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.