Code Golf at Bath Ruby User Group

Golf: normally, unless it’s of the ‘Crazy’ or ‘Adventure’ variety (is there a difference?), I will stay well away from it. That’s mainly because my arms don’t swing and it involves quite a lot of standing and waiting around outside. However, yesterday evening I played a game of Code Golf.

The game goes like this – there are 9 problems (or ‘holes’ if you will), and you need to write a method to solve each one. The problems are fairly simple (I was reminded of first year programming), but the aim was to solve the problems in the fewest number of characters possible. This meant if you stood any chance of winning, you would have to squash your code into something compact and unreadable.

Before the event, I spent most of the day at work where I’m sat in front of the computer typing away at the keyboard for hours at a time. Then after work, I made my way to the Guild then carried on typing away at the keyboard for a couple more hours. I should probably go outside more.

Anyway, after those 2 hours, my laptop’s battery decided to die, and I foolishly hadn’t brought my charger. That was me down and out.

Considering this was only the second time I had ever used Ruby, I think I did pretty well. The time before was on an Introduction to Ruby talk by OxRUG. Those notes came in very handy, as did Google and Stackoverflow.

Task 2 was my favourite (I only managed to attempt the first 3). This was to write a function that took 2 numbers as a range and return the numbers within that range that were also palindromes e.g. between 100 and 150, the numbers 101, 111, 121, 131, 141 are palindromes.

I thought my answer was pretty neat at 152 characters

…but the winner got his down to a mere 62!

Next time, I must remember to bring my charger!

In order to make Code Golf such a success, a lot of preparation had to be done before the event. Huge thanks to Andrew Nesbitt for putting it all together!

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s