Solving Facebook Programming Puzzles using Ruby

I really enjoy solving puzzles. That’s probably what drove me to become a software developer. So I was thrilled to learn that Facebook has a series of programming puzzles. Once you solve a puzzle, you email your code to Facebook and they email you back your results. What follows are the steps that I took to get my computer setup, solve my first puzzle, and submit it to Facebook for testing. It’s important to note that while I primarily work in the .NET world, the Facebook Puzzle bot doesn’t do .NET. This gave the opportunity choose a new language to learn from their list of supported languages (I chose Ruby).

General information about the Facebook Puzzles are at http://www.facebook.com/careers/puzzles.php

1) Download Ruby-1.8.6 from http://www.ruby-lang.org/en/downloads/

2) Next I picked the puzzle I was going to work on. For my first one I picked Hoppity http://www.facebook.com/careers/puzzles.php#!/careers/puzzles.php?puzzle_id=7

My solution looked like this:

).gets.to_i
1.upto(n) do |i|
    if i % 3 == 0 && i % 5 == 0
        print "Hop\n"
    elsif i % 3 == 0
        print "Hoppity\n"
    elsif i % 5 == 0
        print "Hophop\n"
    end
end

3) Then I saved the solution to a file named the same as the keyword on the Facebook puzzles page. In this case, hoppity with no file extension. Source files from scripting languages shouldn’t have a file extension when they are submitted.

You can test the solution by creating a sample input file and calling Ruby from the Ruby command line like this:

David Eisenstat has some more information on his site http://www.davideisenstat.com/fbpfaq/. Including more information on how to submit solutions for compiled languages.

4) Finally, email the file to {0xFACEB00C>>2 in decimal}@fb.com (or 1051962371@fb.com). Once the puzzle engine processes your submission you’ll receive an email with the results.

I hope that you enjoy solving these puzzles as much as I do. And who knows, maybe you’ll even learn something. ;-)

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 )

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