Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / Ruby

Solving Facebook Programming Puzzles using Ruby

5.00/5 (1 vote)
2 Apr 2011CPOL1 min read 10.3K  
How to solve Facebook programming puzzles using Ruby

I really enjoy solving puzzles. That’s probably what drove me to becoming 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.

My solution looked like this:

#!/usr/bin/env ruby
n = File.open(ARGV[0]).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

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.

  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
  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 scripted languages shouldn’t have a file extension when they are submitted.
  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. ;-)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)